Java Interview Questions
- -2of 2 votes
AnswersWhat is system.gc() and runtime.gc() ?
- zammer May 16, 2013 in India for SDET| Report Duplicate | Flag | PURGE
Expedia Software Engineer in Test Java - 0of 0 votes
AnswersCreate a method which accept a integer as a argument and print on console. This method is accessed by multiple threads. If two or more threads call the method with same value then only one thread should allow to print the value other threads should wait. If values are different then all threads should allow to print the value.
- Prashant Kesarwani May 10, 2013 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Associate Java - 0of 0 votes
AnswersHow can you make thread safe to 3rd party library javaclass.
- Razz May 05, 2013 in India| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Java - 1of 1 vote
AnswersImplement circular queue in Java such that:
- Razz May 05, 2013 in India
1. It should work in multithreaaded environment.
2. If one thread performing EnQueue operation and if queue are full then it should wait untill other not emptied the queue.
3. If some thread tring to do Dequeue operation and if queue is empty, then that thread should wait untill other thread can fill atleast one element in queue.| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Java - 0of 0 votes
AnswersWrite a Program such that
- Razz May 05, 2013 in India
1. Thread T1 and T2 are doing job J1 and J2 respectively.
2. Job J2 can't be start by J2 untill job J1 is done by J1.
3. Write code without using Join() method.| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Java - 0of 0 votes
AnswersWhat design pattern does AOP use?
- cCAACc May 04, 2013 in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersYou have two class A and B in a jar file and you have no source code with you. Write a class C which will rewrite the behaviour of the methods in A and B. You are not allowed to write any other class or interface.
- cCAACc May 04, 2013 in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersWrite program of thread pool.
- cCAACc May 04, 2013 in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersWhy do we have both checked exception and Runtime Exception? What will happen if we have only one of a kind?
- cCAACc May 04, 2013 in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersWhat is stale object in Java? How will you handle it? For example: You have a Class A as shown below
- cCAACc May 04, 2013 in United States
public class A{
A(){
// code for database connection
}
// code for other method
}
Now,you are trying to create a object A by its constructor. To initialize constructor it throws some exception to create database connection.
A obj = new A().
obj.amethod() ;
If obj.amethod() ; will be executed successfully or not ?
How will you stop your code not to use obj?| Report Duplicate | Flag | PURGE
Citigroup Developer Program Engineer Java - 0of 0 votes
Answerswrite a class which exposes only 20 of its Objects containing two methods borrowObject and returnObject .Code must be thread safe.Also write a method to get the number of Live Objects(Objects currently in use by other classes).
- onlinesoumitra April 27, 2013 in United States| Report Duplicate | Flag | PURGE
Samsung Developer Program Engineer Java - 0of 0 votes
AnswerWrite a code in java to design connection pool. You have to pass the parameter like pool size, time out etc.
- cCAACc April 20, 2013 in United States
How will you call the connection from pool?Write the code in Java?
How will you return the connection to pool once time out or connection not in use. You also have to write the exception handling mechanism to print any exception.| Report Duplicate | Flag | PURGE
Citigroup Financial Software Developer Java - 0of 0 votes
AnswersWrite a java program to read a file and get different words and also print number of occurences of each word.
- Anil April 17, 2013 in United States| Report Duplicate | Flag | PURGE
Adobe Quality Assurance Engineer Java - 0of 0 votes
AnswersWrite a java program to count the words from the file Othello.txt
- guru sishyan April 16, 2013 in India
- Have the stop words library to filter the words like (to, the, and). (We do not want to count these words)
- Measure the time taken to execute the code.
Small input (From File) : othello.txt
Output (In Console) :
Welcome - 1
bhive -1
community - 2
Join -1
win - 1
exciting - 1
prizes -1
Time Taken: 100 milliseconds
Bigger Input (From File) : othello.txt
Does your code execute within 10 seconds?.| Report Duplicate | Flag | PURGE
Java - 2of 2 votes
AnswersQ: The New operator...how does it work, what are the steps?
- Aditya April 14, 2013 in United States
A: I just said it creates a new memory in the heap and the reference points to it. He seemed satisfied.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Java - -2of 2 votes
AnswersIn a 5*4 matrix what is the most optimal way of traversal and compare the time complexity for different solution ?
- ctrlV April 13, 2013 in United States| Report Duplicate | Flag | PURGE
Sears Holding Intern Java - 0of 0 votes
AnswersCreate a Session Manager class that iterates thru Session objects throw stale sessions out - How would you automatically purge Session objects that have not been active for 30 seconds or (n) seconds? The answer needs to handle millions of sessions.
- tsvi170 April 12, 2013 in United States for EBS| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersLength is given as input.Print all possible permutations of numbers between 0-9.
- Beginner April 11, 2013 in United States
Eg: if input length=4
all possible combinations can be 0123, 1234, 5678,9864,...etc all combinations of length from in all numbers between 0-9| Report Duplicate | Flag | PURGE
Amazon Java - 0of 0 votes
AnswerLet's say you have a fixed thread pool of size 1, internally how does this threadPool work? How is that the same thread gets used again and again.
-------
My answer: The run() methods from various classes are loaded on to a task Queue. As and when the tasks get added to to this queue, the thread keeps on acting on this queue.
Something like:
Queue qTask = new Queue();
qTask.enqueue(object1.method1());
qTask.enqueue(object2.method2());
...
- xankar April 11, 2013 in United Statespublic void run(){ while(true){ if (qTask == null or empty){ wait() } //Take tasks out of qTask }
| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersWhat are the disadvantages/limitations of a ConcurrentHashmap in JAVA?
- xankar April 11, 2013 in United States| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersYou have two sorted list A and B.
- xankar April 07, 2013 in United States
A = [1, 3, 4, 6,8,10, 17, 34]
B = [2, 8, 17, 33, 44, 66, 89, 100, 123]
Write a program to print those numbers which are
1) in A and not in B
2) in B and not in A
Eg: After print: 1 , 3 , 4 , 6 , 10, 33, 34, 44,, 66, 89, 100, 123
I was asked to write this in JAVA.| Report Duplicate | Flag | PURGE
Morgan Stanley Senior Software Development Engineer Algorithm Java - 1of 1 vote
AnswersIf an N X N matrix is given, print it in spiral order.
- GKR April 07, 2013 in United States
Example: Below is 5 X 5 matrix
i l o v e
d i n t e
n i e e p
a v w r i
m a x e c
Print in spiral order. Output is iloveepicexamandinterview| Report Duplicate | Flag | PURGE
Epic Systems Algorithm C C++ C# Coding Java - 0of 0 votes
AnswersThere is a SRT file having timestamp and dialogue .
- zammer April 06, 2013 in India for NA
eg . hh:mm:ss , dialogue .
Suppose the movie runs ahead of dialogue . How or what will the approach to make it equivalent with the movie running .
For eg : The movie time is 02: 58:59 and the dialogue is 5 sec delayed.| Report Duplicate | Flag | PURGE
Blue Jeans Software Engineer in Test Java - 0of 0 votes
AnswersSpecial Property Numbers:
- BeginnerInProgrammingWorld April 06, 2013 in United States
Eg--> You have a number 8987656 or 4565676
The difference between consecutive numbers is either 1 or -1.
You are given a range, you need to print the numbers with this special property.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersThis is on Additive Number Property
- BeginnerInProgrammingWorld April 06, 2013 in United States
Additive Number examples:
123459 (1+2=3, 4+5=9)
314538 (3+1=4, 5+3=8)
122436 (12+24=36)
You are given a range, you need to print all the additive numbers.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersYou are given a 2-D array with same number of rows and columns. You have to determine the longest snake in the array. The property to find the snake is the difference between the adjacent(left, right, up or down) should be either 1 or -1. If there are more than one snakes with maximum length, the output should print both of them.
- BeginnerInProgrammingWorld April 06, 2013 in United States
Example-->
The given array elements are as follows:
4 7 9 8
5 6 5 4
6 7 8 5
10 9 7 6
The longest snakes are 7->6->5->4->5->6 and 7->6->7->6->5->4| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersWhat all design pattern you know. I said i know only singleton.
- PCB April 05, 2013 in India
They asked me to explain Singleton design pattern.| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java - 0of 0 votes
AnswersWhat are wait, notify and notifyAll methods?
- PCB April 05, 2013 in India
Explain one scenario where do you use these methods?| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java - 0of 0 votes
AnswersHow subString works in String class.
- PCB April 05, 2013 in India
subString will not create new string. Class string is having offset and count integers to point to begin index and number of characters.
subString will set these offset and count.| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java - 0of 0 votes
AnswersExplain equlas & hashcode methods. When you will override these two methods?
- PCB April 05, 2013 in India
This same question was asked in other two face to face interviews also. You should know how HashMap actually works. Like collision, put, get.
How to increase HashMap performance.| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java