## Java Interview Questions

- 0of 0 votes
write a java program display the sub string from a string without using string function

- 0of 0 votes
Have you done debugging in JVM? How would you do it.

- 0of 0 votes
what's use of equals and hashcode function?

- 0of 0 votes
hashmap implementation?

- 0of 0 votes
vector vs arraylist

- 0of 0 votes
hashtable vs hashmap

- 0of 0 votes
Is memory leaks possible in Java?

- 0of 0 votes
How Garbage collector know if something is not used and needs to be removed?

- 0of 0 votes
difference between java7 and java8?

- 0of 0 votes
java vs javascript

- 0of 0 votes
stack vs heap

- 0of 0 votes
Does JavaScript has inheritance?

Can you override in JavaScript?

- 0of 0 votes
What's difference between Javascript and JAVA in terms of OOP principles. Provide examples.

- 0of 0 votes
If given a binary file, with data like lat, long, weather, temp in key:value. It's a structured data how would u ingest it. what are the steps that are being taken before Hive process starts.

- serde (serializartion deserialization). parque etc.

- 0of 0 votes
After map phase partition, shifting, sorting happen. What does it mean?

- 0of 0 votes
What is input split in hadoop.

- 0of 0 votes
As I interviewing for Big data position. Asked Hadoop question :-

Difference between TextInput vs Key Value format in Hadoop.

- 0of 0 votes
Design Bing search.

- 0of 0 votes
What's Hbase, Pig, used for? Why do we need Hbase if we can use Hive to query Hadoop?

- 0of 0 votes
What are different phases of Map reduce operation - I think they were looking for split, combiners, partitioners, sorting phases of whole map reduce stage.

- 0of 0 votes
My interview was for big data position for their Search team. They were looking for person with good Hadoop skill set :-

1. Can you describe Hadoop Architecture? What are various components of it (Primary/Secondary namednodes, data node etc)? Explain working of each.

- 0of 0 votes
Given Two classes A & B. How will B know if an instance of A is already created?

- 0of 0 votes
Suppose you are given a puzzle that is represented as a matrix with 0s and 1s, where a 0 indicates you’re allowed to move into that position and 1 means you’re not allowed to move in that position. Write a function that given a start position and an end position, returns a boolean value indicating if there exists a path from start to end. you are only allowed to move up, left, right and down. Diagonal movement is not allowed.

Example #1

Input

0 0 1 0 1

0 0 0 0 0

0 1 1 1 1

0 1 1 0 0

start: 4,1

end 0,3

Output - true

Example #2

Input

0 0 1 1 1

0 1 0 0 0

1 1 1 1 1

0 0 0 0 1

start: 0,0

end: 1,2

Output - false

- 1of 1 vote
Implement a function that returns the i-th most popular item sold

at xyz company. You cannot rely on any libraries.

Class Item {

String itemId;

int quantitySold;

}

/**

find the i-th most popular item in the list

**/

String find(List<Item> items, int i) {

// your code goes here

}

- 0of 2 votes
I have this element {1, 1, 2, 3}, so i have an duplicate element. I want generate combinations and my result should be: {1} {2} {3} {1 1} {1 2} {1 3} {2 3} {1 1 2} {1 1 3} {1 2 3} {1 1 2 3}. The order of element isn't important, {1 1 2 3} == {2 3 1 1}, but i wan't a duplicate result set.

My code is:

enter code herepublic List> powerSet1(List originalSet) { Date inizio = new Date(); int resultSize = (int) Math.pow(2, originalSet.size()); // resultPowerSet is what we will return List> resultPowerSet = new ArrayList>(resultSize);

// Initialize result with the empty set, which powersets contain by definition

resultPowerSet.add(new ArrayList<Elemento>(0));

// for every item in the original list

for (Elemento itemFromOriginalSet : originalSet) {

// iterate through the existing powerset result

// loop through subset and append to the resultPowerset as we go

// must remember size at the beginning, before we append new elements

int startingResultSize = resultPowerSet.size();

for (int i=0; i<startingResultSize; i++) {

// start with an existing element of the powerset

List<Elemento> oldSubset = resultPowerSet.get(i);

// create a new element by adding a new item from the original list

List<Elemento> newSubset = new ArrayList<Elemento>(oldSubset);

newSubset.add(itemFromOriginalSet);

// add this element to the result powerset (past startingResultSize)

resultPowerSet.add(newSubset);

}

}

logger.info(resultPowerSet);

Date fine = new Date();

long tempo = fine.getTime() - inizio.getTime();

logger.info ("durata genera combinazioni: " + tempo);

return resultPowerSet;

}

But this generate duplicate.

- 0of 0 votes
In a Formula-1 challenge, there are n teams numbered 1 to n. Each team has a car and a driver. Car’s specification are as follows:

– Top speed: (150 + 10 * i) km per hour

– Acceleration: (2 * i) meter per second square.

– Handling factor (hf) = 0.8

– Nitro : Increases the speed to double or top speed, whichever is less. Can be used only once.

Here i is the team number.

The cars line up for the race. The start line for (i + 1)th car is 200 * i meters behind the ith car.

All of them start at the same time and try to attain their top speed. A re-assessment of the positions is done every 2 seconds(So even if the car has crossed the finish line in between, you’ll get to know after 2 seconds). During this assessment, each driver checks if there is any car within 10 meters of his car, his speed reduces to: hf * (speed at that moment). Also, if the driver notices that he is the last one on the race, he uses ‘nitro’.

Taking the number of teams and length of track as the input, Calculate the final speeds and the corresponding completion times.

- -1of 1 vote
consider a battlefield to be made up of square cells of unit dimensions. a soldier on the battlefield can move from a cell to all(8) of it's neighboring cells. soldier has a gun with with him which he can shoot the targets up to any distance along any of the 8 possible directions (north,east,west,south,north-east,north- west,south- east,south- west). also some sell are bulletproof which prevents bullets to pass but soldier can walk over them as if it were a normal cell.he can destroy the target from a bulletproof cell but not from a cell behind it.

position of a target/ soldier can be given by the cell, they are on.given the position of the target, starting position of a target and position of all the bullet proof cells. you have to tell the position of closest shooting point i.e the cell from which, the soldier can shoot the target and is closest to the starting position of the soldier. if there are more than such cells, output all of them.

Input/output specifications :

Input specifications :

I) size of the battlefield { integer pair (N,M) : battlefield will be of N*M size )

II) staring position of the soldier {integer pair (i,j)}

III) position of the target {integer pair (x,y) : position of the cell on which target is mounted}

IV) position of the all bullet proof cells { list of integer pair a#b : each element in the list is a position of bullet proof cells }

output specifications :

sequential list of integer pair i#j (cell) that are closest shoot points and must fallow row wise traversal.

Note: if the output list contains four shoot points : (2,1), (1,2), (3,2), (2,4) on a 4x4 battle field.

then the correct output will be {1#2,2#1,2#4,3#2} not {1#2,2#1,3#2,2#4}

Examples:

Input : {2,2} {2,1} {2,2} {1#1,1#2}

output : 2#1

below is the method signature in java:

public static String[] nearest_shoot_point(int[] input1,int[] input2,int[] input3String[] input4){

}

- 0of 0 votes
You are given two objects, Student and Course, and there exist a many to many relation between them. One student can be enrolled for more than one course and there can be many students enrolled for a single course. Design an effective data structure to store such data keeping in mind that the time complexity for search should be optimum. A search can be for the list of students enrolled for a single course, or for the list of courses a single student is enrolled.

- 1of 1 vote
The prime numbers between 1,000,000 and 1,000,100 are:

1000003, 1000033, 1000037,1000039, 1000081, 1000099

and its sum is = 6000292.

What is the sum of all prime numbers between 1,000,000,000,000 and 1,000,000,100,000?

- 0of 0 votes
You are given the Ancestor matrix of a Binary tree, write an C program/function to construct the corresponding tree.

For example, the below tree:

10

/ \

5 30

/ \ \

4 8 40

/

1

Will have the following ancestor Matrix

1 4 5 8 10 30 40

1 0 1 1 0 1 0 0

4 0 0 1 0 1 0 0

5 0 0 0 0 1 0 0

8 0 0 1 0 1 0 0

10 0 0 0 0 0 0 0

30 0 0 0 0 1 0 0

40 0 0 0 0 1 1 0

Essentially, in the ancestor matrix, each node has a row and a column (may not be the same). The value at a[i][j] will be 1 iff node of Node representing j‘th column is the ancestor of node representing the i‘th row.

Write an C program/function that can construct the binary tree from a given Ancestor matrix(2 dimensional array as input to the function).