Java Interview Questions
- 0of 0 votes
AnswersImplement Iterator class with peek() functionality in Java.
- hasan.tanpinar April 04, 2013 in United States| Report Duplicate | Flag | PURGE
Google Intern Software Engineer / Developer Java - 0of 0 votes
AnswersWhere is primitive data stored in java memory?
- ab April 03, 2013 in United States| Report Duplicate | Flag | PURGE
Harman Kadron Java Developer Java - 0of 0 votes
AnswersRemove duplicates from an array say {1,2,7, 9, 9, 5, 4, 9} and create a new array and put the values in the new array. Note: Not to use any collection classes. Space and time complexity needs to be considered.
- rizwan.amd March 25, 2013 in India| Report Duplicate | Flag | PURGE
United HealthGroup Tech Lead Java - 0of 0 votes
AnswersWrite a method to evaluate if a given integer is prime.
- alex@kiwox.cl March 22, 2013 in Chile for Kiwox| Report Duplicate | Flag | PURGE
Kiwox Software Engineer / Developer Java - 3of 3 votes
AnswersCoding:
Public void TransferAccount(AccountID id1, AccountID id2){ Account a1 = id1.GetAccount(); Account a2 = id2.GetAccount(); //Swap amounts. Temp = a1.Balance; a1.Balance = a2.Balance; a2.Balance = Temp; }
Q1: How do you make it thread safe?
I said use “public void synchronized” Good. But terrible performance since the entire method is synchronized.
Q2: Can you not lock on the entire method? I said used nested locks:Synchonized(a1) Synchronized(a2) { //swap }
His q: This will lead to a deadlock if in another thread I call Transfer (id2, id1) and Transfer (id1, id2).
Synchonized(a1) Synchronized(a2) { //swap }
Synchonized(a2) Synchronized(a1) { //swap }
How do you prevent this then? How do you design your code to not to get in to deadlock? (stumbled here)
- xankar March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Java Threads - 0of 0 votes
AnswersHow do you detect deadlocks? What tools would you use? I said do “Kill -3 .<process id>, and analyse if anything is deadlocked.
- xankar March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java Threads - 0of 2 votes
Answers3) Coding question:
public class ThreadingQuestion extends Thread { public static void main(String[] args) { public static boolean flagRun = true; new thread { void run(){ while (flagRun) //do something }.start() flagRun = false; }
Will the thread spawned will ever see the flagRun=false?
- xankar March 16, 2013 in United States
My corrected answer after a couple of attempts: No, since each thread will get a copy of it’s own flagRun, changing the flagRun value in the main thread will not be seen in the spawned thread.
How to fix it: declare flagRun to be volatile so that the values can be changed and seen in either threads.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 1of 1 vote
AnswersWhat is difference between "volatile" and "static volatile"? Give an example
- xankar March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersExplain what is “static synchronized?” What does it lock on? what is ‘synchronized’? what does it lock on?
- xankar March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersEach time a visitor requests a page from our website, our webserver writes a log entry recoding the visitor's identity and the kind of page requested. Entries are written in chronological order to a plain-text file, with one entry per line. The format of each entry is:
- jimmy514in March 14, 2013 in United States
user-id page-type-id
User IDs are arbitrary strings that uniquely represent a given user; if a user visits multiple pages, each log entry will have the same user ID. Page type IDs are arbitrary strings that uniquely represent a given kind of page on our site, such as the homepage, a product detail pages, or the shopping cart. Tons of users visit our website, but there are only a few dozen types of pages.
We can use our weblogs to answer questions about user behavior. One interesting question is: what is the most common three page sequence through the site? E.g., if the most common pattern is to buy items advertised on the home page of the site, we might see the most common three page sequence as "Homepage -> ProductDetailPage -> ShoppingCart". However, if customers spend a lot of time browsing the "Customers who bought this item also bought" feature, we might see the most common three page sequence as "ProductDetailPage -> ProductDetailPage -> ProductDetailPage".
Attached is a sample log file for your reference. Within the first 10 lines of the sample, customer "234" travels through the sequences "Listmania -> ProductDetail -> Checkout" and "ProductDetail -> Checkout -> HomePage" once each.
For the sake of this test feel free to assume that everything will fit in memory. Do keep in mind that given the size of our data sets, performance has to be considered, also, we will be looking at more than just correct output..| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Java - 3of 3 votes
AnswersWrite a program to sort an array of strings so that all anagrams are next to each other
- Neo March 07, 2013 in United States for Web Service
ex
input {god, dog, abc, cab, man}
output {abc, cab, dog, god, man}| Report Duplicate | Flag | PURGE
Amazon Intern C++ Java - 0of 0 votes
AnswersHow will you synchronize 3rd party library from your application..
- Razz March 07, 2013 in India| Report Duplicate | Flag | PURGE
Oracle Software Engineer / Developer Java - 2of 4 votes
Answersfind the substring count from a string without string functions in java?
- Neo March 05, 2013 in United States
Given String str = "abcdefghcde";
String find = "cde";
Count occurrences of cde in String str| Report Duplicate | Flag | PURGE
Salesforce Software Engineer Intern Java - 0of 0 votes
AnswersUsing two threads you should print "Hello World Hello World Hello World Hello World Hello World Hello World ".
- PCB March 05, 2013 in India for ISL
In two threads one should print "Hello: and another thread "World".| Report Duplicate | Flag | PURGE
IBM Developer Program Engineer Java - 0of 0 votes
Answerswhat is use of command line argument in software development.
- rohit March 01, 2013 in India
give any real example where we must use command line argrment (for ex- any system software,application software etc)| Report Duplicate | Flag | PURGE
IBM Software Development Manager Java - 0of 0 votes
AnswersWe consider a Permutation of first 'N' natural numbers 'good' if it doesn't have 'x' and 'x+1' appearing consecutively, where (1 <= x <= N).
- sharathvasa February 12, 2013
• For Example, For N=3, all 'good' permutations are:
1. {1,3,2}
2. {2,1,3}
3. {3,2,1}| Report Duplicate | Flag | PURGE
Software Engineer / Developer Java - 0of 0 votes
Answers1. What is a Hash Map..? Describe its two implementation.
- A February 01, 2013 in United States
2. Difference between Arraylist and linkedlist in JAVA.
3. Discuss issues in implementing HashMaps...collisions mainly...and how to fix them.
4. What is run-time polymorphism in JAVA..explain with example.| Report Duplicate | Flag | PURGE
Intern Java - 0of 0 votes
AnswersHow to maintain a Singleton in clustered environment
- vasa.v03 January 28, 2013 in India| Report Duplicate | Flag | PURGE
Ebay Member Technical Staff Java - 0of 0 votes
AnswersProgram to calculate a power n
- vasa.v03 January 28, 2013 in United States| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersProgram to calculate a pow n...
I gave a answer with O(logN)
- vasa.v03 January 28, 2013 in Indiapublic static long exp(int a , int n) { boolean is_N_Odd = false; if ( n % 2 > 0 ) { n++; is_N_Odd =true; } if ( n == 2 ) return a * a; else if (n == 1 ) return a; else { long calc = exp (a , n/2) ; if ( is_N_Odd ) return calc * calc /a; else return calc * calc ; } }
| Report Duplicate | Flag | PURGE
Ebay Member Technical Staff Java - 0of 0 votes
AnswerHow to maintain locks/monitors in clustered environment ?
- vasa.v03 January 28, 2013 in India| Report Duplicate | Flag | PURGE
Ebay Member Technical Staff Java - 0of 0 votes
AnswerHow to manage a singleton in clustered environment ?
- vasa.v03 January 28, 2013 in India| Report Duplicate | Flag | PURGE
Ebay Member Technical Staff Java - 0of 0 votes
AnswersTime complexity of Hash Map storage and retrieval in Java.
- Saurabh January 28, 2013 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Java - 1of 1 vote
AnswersWhat are immutable objects? What are their Advantages? Design a immutable object with Date object as a member attribute. NOTE : Since Date is mutable, he wanted to check whether I could resolve that. I dint though :(
- Saurabh January 28, 2013 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Java Object Oriented Design - 0of 0 votes
AnswersWhich Design patterns have you worked on? What is Singleton? Design a Singleton Class. Make it thread safe.
- Saurabh January 28, 2013 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Java Knowledge Based - 0of 0 votes
AnswersWhats the difference between Semaphore and Lock in Java?
- ganesh January 22, 2013 in United States| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersYou have a web server's log that records for each user the URL that he accessed.
Example format:Time-stamp User-id URL
How to find the maximum common (sub)sequence of visited URLs from all users? Write code in java
Log entries are ordered based on timestamp.
Example log (omitting timestamp for clarity):
John URL1
John URL2
Jim URL2
Mary URL1
John URL4
etc
Update:
Example:User-id URL 186 A 187 B 186 C 188 B 186 C 187 A 186 B 188 A 188 C 189 A 189 D 187 C 189 B 186 A 187 C 189 A 189 C
So the max common URL sequence is A,C,C (URL A followed by URL C, followed by URL C)
- Jim January 20, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 0of 0 votes
AnswersDesign Online Movie Booking System.
- ganesh January 19, 2013 in United States| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersGiven a file, we have to replace a word with another word.
- ganesh January 16, 2013 in India| Report Duplicate | Flag | PURGE
Thomson Reuters Software Engineer / Developer Java - 0of 0 votes
AnswersWhat is difference between oops and ooad?
- aashish January 03, 2013 in United States| Report Duplicate | Flag | PURGE
Java