Java Interview Questions
0of 0 votes1. What is a Hash Map..? Describe its two implementation.
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.
0of 0 votesHow to maintain a Singleton in clustered environment
0of 0 votesProgram to calculate a power n
0of 0 votesProgram to calculate a pow n...
I gave a answer with O(logN)public 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 ; } }
0of 0 votesHow to maintain locks/monitors in clustered environment ?
0of 0 votesHow to manage a singleton in clustered environment ?
0of 0 votesTime complexity of Hash Map storage and retrieval in Java.
0of 0 votesWhat 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 :(
0of 0 votesWhich Design patterns have you worked on? What is Singleton? Design a Singleton Class. Make it thread safe.
0of 0 votesWhats the difference between Semaphore and Lock in Java?
0of 0 votesYou 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)
0of 0 votesDesign Online Movie Booking System.
0of 0 votesGiven a file, we have to replace a word with another word.
0of 0 votesWhat is difference between oops and ooad?
0of 0 votesDifference between applets and application.
0of 0 votesWrite a program to shuffle a deck of 52 cards and shuffle them equally to 4 players
0of 0 votesWrite a program that takes an array of numbers, and then prints out all the possible pairs of numbers that sum up to the value N.
E.g., if the array contains the numbers {0, 1, 2, 2, 3, 4, 5} and the target value N is 4, then the output would be (0, 4), (1, 3), (2, 2).
0of 0 votesI have two threads, both contain data from a database table. One thread performs some operation and update the data in the database table whereas second thread has not yet done any operation. Second thread does operation after some time and wants to update the operation. Since the first thread has already updated the data in the database table, second thread has stale data. How can we manage so that table should have the actual data not the stale data.
0of 0 votesint n=99;
int unsignedShift = n>>>2;
System.out.println("unsignedShift="+unsignedShift);
The above result gives "unsignedShift=24". The question is if 24 is given how can I get back the original value ie n ie 99. How to do it for both positive and negative integer. How to do it in java.
0of 0 votesPhonebook contains number and name.
1.use the java collection to add these entry (name and string).
2.Search the name by number
3.Remove the entry (name and string ) by using name.
I need to do this in Java...But if you can suggest me some Collection that can be used here, I shall do that....
I thought of :
1.using Hashmap,but here both name and number will be key....which wont be good...
2.Another option is to wrap both phone and number in an object and then add them to the list.And then Iterating and adding to the list.
Any other suggestions..?
0of 0 votesPrint below series in java
*** 1***
**2 *2**
*3*3*3*
4*4*4*4
0of 0 votesThis was at a recent written test...
There is a toycar placed on a 5 by 5 board.We can give 5 commands to it ,
PLACE(X,Y,F) where x denotes X Axis,y denotes Y Axis and F denotes the direction to which its facing.
MOVE->Move will move the toycar one step in the direction where its facing
LEFT->Left will turn the toycar by 90 degrees to its left and face it to the new direction .Note:Left will not move the toycar, it will just change the direction
RIGHT->Right will turn the toycar by 90 degrees to its right and face it to the new direction .Note:Right will not move the toycar, it will just change the direction
REPORT->Report shall tell me the X Axis,YAxis and Direction of the toycar. like 0,0,NORTH
Note:You cannot move,left,right,report the toycar unless you place it.
Assume its a Prod level code, Solve it in Java only.
Below is my code and I haven't been selected, please tell me if there is better way to do it because my solution is correct but probably very basic.Thanks.package com.ds; public class ToyCar { private ToyCar toycar; private boolean isToyPlaced; private int xAxis,yAxis; private enum Direction {EAST,WEST,NORTH,SOUTH}; private Direction direction; public int getxAxis() { return xAxis; } public void setxAxis(int xAxis) { this.xAxis = xAxis; } public int getyAxis() { return yAxis; } public void setyAxis(int yAxis) { this.yAxis = yAxis; } public Direction getDirection() { return direction; } public void setDirection(Direction direction) { this.direction = direction; } ToyCar(){ } public ToyCar(int xAxis,int yAxis,Direction direction) { this.xAxis=xAxis; this.yAxis=yAxis; this.direction=direction; } public void place(int x,int y, Direction d){ if(x<0||x>5||y<0||y>5 || d==null){ System.out.println("Place Error:Attempt to place toy outside the box"); return; } toycar = new ToyCar(x, y, d); isToyPlaced=true; } public void move(){ if(!isToyPlaced){ System.out.println("Move Error:Attempt to Move Toy without placing in board"); return; } if(toycar.getDirection().equals(Direction.EAST)){ int newPosition=toycar.getxAxis()+1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setxAxis(newPosition); }else if(toycar.getDirection().equals(Direction.WEST)){ int newPosition=toycar.getxAxis()-1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setxAxis(newPosition); }else if(toycar.getDirection().equals(Direction.NORTH)){ int newPosition=toycar.getyAxis()+1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setyAxis(newPosition); }else if(toycar.getDirection().equals(Direction.SOUTH)){ int newPosition=toycar.getyAxis()-1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setyAxis(newPosition); } } public void left(){ if(!isToyPlaced){ System.out.println("Left Error:Attempt to Move Toy without placing in board"); } if(toycar.getDirection().equals(Direction.EAST)){ toycar.setDirection(Direction.NORTH); } else if(toycar.getDirection().equals(Direction.WEST)){ toycar.setDirection(Direction.SOUTH); } else if(toycar.getDirection().equals(Direction.NORTH)){ toycar.setDirection(Direction.WEST); } else if(toycar.getDirection().equals(Direction.SOUTH)){ toycar.setDirection(Direction.EAST); } } public void right(){ if(!isToyPlaced){ System.out.println("Right Error:Attempt to Move Toy without placing in board"); } if(toycar.getDirection().equals(Direction.EAST)){ toycar.setDirection(Direction.SOUTH); } else if(toycar.getDirection().equals(Direction.WEST)){ toycar.setDirection(Direction.NORTH); } else if(toycar.getDirection().equals(Direction.NORTH)){ toycar.setDirection(Direction.EAST); } else if(toycar.getDirection().equals(Direction.SOUTH)){ toycar.setDirection(Direction.WEST); } } public void report(){ if(!isToyPlaced){ System.out.println("Report Error:How can i report when I am not on board"); return ; } System.out.println(toycar.getxAxis()+" , "+toycar.getyAxis()+" , "+toycar.getDirection()); } public static void main(String[] args){ ToyCar to = new ToyCar(); to.place(0, 0, Direction.WEST); to.left(); to.move(); to.report(); } }
0of 0 votesWhy character array is better than string for storing password in java?
0of 0 votesFind the union of non-overlapping ranges,
e.g; given an array {0,3,1,5,7,9,8,13} where 0 is starting point and 3 is the end point and so on.
The output should be {0,5,7,13}
0of 0 votesI have Created Dynamic Web Application...
there is user table with column "enabled" to check if the user is already logged in
enabled = true --> logged in otherwise not
if i logged in , i cannot loggin at the same time in anothe r browser ..
but if i logged in and close the browser, how can i handle further loggin ??
0of 0 votes1. Remove the words where last character is a capital letter from a given sentence and then reverse the characters of each word
0of 0 votesFrom a given a sentence, find the word which contains more than 1 vowels and print all special characters.
Input: This is a test sentence, good luck.
Output: Total words which contain more than 1 vowels: 2
The special characters are: , .
0of 0 votesFrom a given string of numeric values, print the individual numbers in words separated by space.
Input: “2490”
Output: two four nine zero
0of 0 votesHow inter-thread communication can be done?
0of 0 votesDifference between == and equals
