cCAACc
BAN USER
- 0of 0 votes
AnswersDesign the below scenario in Java.
- cCAACc in United States
In an Olympic event there is a running track and it is used for 100m,200m,400m. You have 10 participants.
When the event start , capture the time taken by each participants. Determine who is the winner in each event.| Report Duplicate | Flag | PURGE
Barclays Capital Solutions Architect Object Oriented Design - 0of 0 votes
AnswersDesign the below scenario in Java.
- cCAACc in United States
You have to maintain the family tree of 10 generation. For a family you have to store father, mother and their children.
You have do the following operation.
When you search by a particular name of father/children, It will print whole 10 generation.
Calculate the time and space efficiency of your search operation.| Report Duplicate | Flag | PURGE
Barclays Capital Solutions Architect Object Oriented Design - 0of 0 votes
AnswersWhat design pattern does AOP use?
- cCAACc 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 in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersWrite program of thread pool.
- cCAACc in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Java - 0of 0 votes
AnswersYou have an array Char[] chArray = {'a','a','b','c','a','b','d','c','c','d','a','a'}
- cCAACc in United States
Write a program to remove the duplicate and the output should be as per the below:
{'a','b','c','d','','','','','','',''} . You should not use any collection api| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer Arrays - 0of 0 votes
AnswersWhat design pattern does Exception handling use and why?
- cCAACc in United States| Report Duplicate | Flag | PURGE
Barclays Capital Senior Software Development Engineer - 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 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 - 1of 1 vote
AnswersDesign a LRU cache in Java.
- cCAACc in United States| Report Duplicate | Flag | PURGE
Citigroup Financial Software Developer - 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 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 - 1of 1 vote
AnswersWrite a SQL to find the nth maximum salary in a employee table.
- cCAACc in United States| Report Duplicate | Flag | PURGE
Citigroup Financial Software Developer SQL - 2of 2 votes
AnswersYou have a very very big text file.How would you read & process it to print the below output.
- cCAACc in United States
1. Print the top ten ranked distinct words.
2. Print the occurrence of the each alphabet in this file.
For example:
ABC (100)
XYZ (40)
PQR (10)
THE (200)
IN (200)
Then I have to display the output as
IN (200)
THE (200)
ABC (100)
XYZ (40).
And
A=1000
B=2000
C= 300
.. ...
z=300| Report Duplicate | Flag | PURGE
Citigroup Financial Software Developer String Manipulation
Agree with hprem991. Could you please clear the requirement?What I have understood. you have the colour as below
{a,a,g,d,v,c,s,d,f,r,h,w,s,r,t,g,f,d,s,d,h}. and you have to arrange like
{a,a,a,a,a,a,a,b,b,b,b,b,b,c,c,c,c,c.....}
Also the accepted space time complexity ....
import java.util.Arrays;
public class TestLoop {
public static void main(String[] args) {
char[] a = {'G','O'};
char[] b = {'G','O','O','G','L','E'};
//remove the duplicate as {' ',' ',' ',' ','L','E'};
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
if(a[i]==b[j]){
b[j]=' ';
}
}
}
// move the ' ' to end.. as {'L','E',' ',' ',' ',' '}
for(int k=0;k<b.length ;k++){
for(int l=k+1;l<b.length;l++)
if(b[k] == ' ' && b[l] != ' ' ){
b[k] = b[l];
b[l] = ' ';
}
}
// now search the first position of ' ' and create sub array from 0 to ii th position
for(int ii=0;ii<b.length;ii++){
if(b[ii] == ' '){
b = Arrays.copyOfRange(b, 0, ii);
break;
}
}
for(int kk=0;kk<b.length;kk++)
System.out.println("-----------:" + b[kk]);
}
}
The safest way is to ensure that only one thread calls into the third-party library at a time - that is, take a mutex around EVERY call to the library. Making it so that multiple threads can use the library at once. This could be implemented using Semaphore.
class Pool {
//you have only one instance.
private static final MAX_AVAILABLE = 1;
private final Semaphore available = new Semaphore(MAX_AVAILABLE, true);
public Object getItem() throws InterruptedException {
available.acquire();
return getNextAvailableItem();
}
public void putItem(Object x) {
if (markAsUnused(x))
available.release();
}
// Not a particularly efficient data structure; just for demo
protected Object[] items = <your third pary library item here.>
protected boolean[] used = new boolean[MAX_AVAILABLE];
protected synchronized Object getNextAvailableItem() {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (!used[i]) {
used[i] = true;
return items[i];
}
}
return null; // not reached
}
protected synchronized boolean markAsUnused(Object item) {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (item == items[i]) {
if (used[i]) {
used[i] = false;
return true;
} else
return false;
}
}
return false;
}
}
http://docs.oracle.com/javase/1.5.0/docs/api/index.html?java/util/concurrent/Semaphore.html
public class Test {
public static void main(String[] args) {
char[] charArr ={'a','b','a','a','c','d',' ','a','e','a','c','b','b','f','g',' '};
//remove the duplicate char by ' '
for(int i=0;i<charArr.length;i++){
for(int j=0;j<charArr.length;j++){
if((i!=j)&& charArr[i] != ' ' && charArr[i]==charArr[j]){
charArr[j] = ' ';
}
}
}
// push the blank to end
for(int k=0;k<charArr.length ;k++){
for(int l=k+1;l<charArr.length;l++)
if(charArr[k] == ' ' && charArr[l] != ' ' ){
charArr[k] = charArr[l];
charArr[l] = ' ';
}
}
for(int ii=0;ii<charArr.length;ii++){
System.out.println("-----------: " + charArr[ii]);
}
}
}
Time complexity is O(n^2)
As file size is very very big, say more than 2 GB, I feel above code is not much efficient.It will take longer time. Instead reading a single file , I would split the file into n number of small files based on the line count. Then , will run your processing logic in a multithread environment , will use fixed thread pool instead of creating many threads. I will use concurrent hash map instead HashMap<String,Interger> to store the word and count.
- cCAACc April 20, 2013
RepArnavPatel, abc at A9
Dedicated and energetic bakery assistant with a passion for flavor and a love for creating. Professional and dependable with more ...
As per my understanding 'Exception handling' use Template method design pattern.
- cCAACc May 05, 2013'Template method design pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithms structure.'
If we see the API source code, Exception handling class in each hierarchy add its own method on the top of parent class.