Java Interview Questions
- -3of 5 votes
AnswersHow can a HashMap accepts caseSensitive value ?
- bipin.gauda August 31, 2013 in India for Bigdata analyst| Report Duplicate | Flag | PURGE
NetApp Analyst Java - -2of 2 votes
AnswersQ? How to find the highest nus. and second highest nus from a file ?
- bipin.gauda August 31, 2013 in India for Bigdata analyst| Report Duplicate | Flag | PURGE
NetApp Analyst Java - -2of 2 votes
AnswersAre the following statements correct in Java.
- trish August 17, 2013 in United States
String firstName = "Joe";
String lastName = new String("Mo");| Report Duplicate | Flag | PURGE
Symantec Principal Software Engineer Java - 0of 0 votes
AnswersGiven a directed labelled graph in form of a knowledge base, and a query, write a parser which can return the edges and/or nodes requested in the query. (Knowledge base and queries are not case sensitive)
Knowledge base is given as input in a text file (input.txt).
For example a DAG can be represented as:
And the corresponding knowledge base for this DAG is :(<Shelden>, <hasFriend>, <Raj>) (<Shelden>, <hasFriend>, <Leonard>) (<Shelden>, <worksAt>, <Caltech>) (<Leonard>, <worksAt>, <Caltech>) (<Raj>, <worksAt>, <Caltech>) (<Raj>, <age>,“30”) [Here 30 is a number and no edge can go out from this node while others like Nabraska, New_Delhi are entities, which can have further outgoing links.] (<Leonard>, <hasFriend>, <Penny>) (<Penny>, <bornIn>, <Nabraska>) (<Raj>, <bornIn>, <New_Delhi>)
A query can be written as :
Find persons who are friends?
Test case 1 : Select ?person1 ?person2 where { ?person1 <hasfriend> ?person2. }
The goal is to fill all the variable represented by ? with their values from knowledge base and return in csv format:
The result of this query is:
Person 1 Person 2
Shelden Raj
Shelden Leonard
Leonard Penny
The similar query can be extended to have joins also:
- abhishek.vk88 August 10, 2013 in United StatesFind persons who are friends with Sheldon and the company/colleges to which his friends belong? Test Case 2 : Select ?person ?university where { <Sheldon> <hasFriend> ?person . ?person <worksAt> ?university. } Person University Leonard Caltech Raj Caltech Test Case 3 : Select ?person1 ?person2 where { ?person1 <worksAt> <Caltech> . ?person2 <bornIn < Nabraska> . ?person1 <hasFriend> ?person2 .} Person 1 Person 2 Leonard Penny Test Case 5 : select * where {} Output : Parse Error How to approach this problem?
| Report Duplicate | Flag | PURGE
Adobe Developer Program Engineer Algorithm Java - 0of 0 votes
AnswersThere are two interfaces B and C each having the same method public m1()
- Ram August 06, 2013 in India for QATeam
class A implements B and C
If class A has to implement method m1, the implemented method would be of which interface?| Report Duplicate | Flag | PURGE
VMWare Inc Quality Assurance Engineer Java - 0of 0 votes
AnswersA method takes two array list as its arguments
- Ram August 06, 2013 in India for QATeam
Both ArrayList have list of objects similar to the example here below
AL1 = {A,A,B,L,C,F,D,E,F,D,Z,R}
AL2 = {C,E,X,Z,M,X,P,L,M,N,S,T,P,B,A}
The aim is to create a third arraylist AL3 which would contain only elements that are occuring exactly twice, even after combining both AL1 and AL2.
So, the resultant list should be as seen here below
AL3 = {B,C,F,D,Z,E,X,P,M}
What logic do we follow?| Report Duplicate | Flag | PURGE
VMWare Inc Quality Assurance Engineer Java - 0of 0 votes
AnswersImplement a method for tranpose of text in a text file as below.
- Syed July 27, 2013 in India for Subex
Text File:
abc
def
gh
--------
------
Its Transpose should display as below
adg
beh
cf
-------
-------| Report Duplicate | Flag | PURGE
Java - -3of 3 votes
AnswersHow can I find the shortest distance between the first and the last element in a two dimension Array of 0's and 1's.
- martin1990 July 20, 2013 in India
Given if the element is 1 we can move left or down, if it is 0 we can only proceed downwar| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer Java - 0of 0 votes
AnswersGiven a list of numbers find the avg of last n numbers.
- coder July 17, 2013 in United States
use data structure which will give best performance| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
Answerswrite a JAVA method that will count the number of duplicate words in a String, and will output the total count.
- coder July 17, 2013 in United States
what data structure do you use?| Report Duplicate | Flag | PURGE
Java - -3of 3 votes
Answersclass Test { public void m1(String arg1){ arg1 = "Am I going to disappear?"; } public static void main (String[] args) { Test test = new Test(); String iAmOfAnArgumentativeNature = "I am born new"; m1(iAmOfAnArgumentativeNature); System.out.print(iAmOfAnArgumentativeNature); } }// end class
What is the output?
- SoMiE July 11, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 0of 0 votes
AnswersIf a java class has methods declared
as followsclass A public synchronized void m1() { //whatever code } public synchronized void m2 { // whatever code } // note that return type is not relevant here.
if a class is created with A a = new A() and
- SoMiE July 11, 2013 in India
if a thread T1 is executing a.m1 and another thread T2 wants to execute a,m2 - what will happen?| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 4of 4 votes
AnswersHow will you calculate the size of the object in java ? I gave answer for the serialized objects. The interviewer then modified the question that an ArrayList contains 10 non-serialized objects. How will you find out which object is the heaviest one ? He again added that the ArrayList is not a generic one, it may contain any kind of object like Organisation, Employee, Salary, PersonalDetails,OfficialDetails etc all object type. Now you have to find out which one is the heavy object through java program. He said there is some way you can measure the size of the object. Please help me.
- Mr D July 09, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 0of 0 votes
AnswersImplement (in C++, MATLAB, or Java) a Fraction class that supports the following operations: addition, subtraction, multiplication, division, equality/non-equality, greater than/less than, and display. The program should take on the order of several hours. If there are techniques that would take longer to implement, note it down as comments.
- AnOnYmOuS June 24, 2013 in India| Report Duplicate | Flag | PURGE
Algorithm C++ Coding Java Math & Computation - -2of 2 votes
AnswersGiven a string T of length n, partition it in n' "phrases" (p1, p2, ..., pn'), such that
- hakkindumma June 21, 2013 in United States
pi = pj + c, for some j<i, where + is string concatenation and c is a character
p0 = ''
p1 = pj + c where j < 1
T = p1 + p2 + ... + pn'
For example:
T = aababcabcd = a + ab + abc + abcd
p1 p2 p3 p4| Report Duplicate | Flag | PURGE
Groupon Developer Program Engineer Algorithm Java String Manipulation - 0of 0 votes
AnswersGiven a list of test results (each with a test date, Student ID, and the student’s Score), return the Final Score for each student. A student’s Final Score is calculated as the average of his/her 5 highest test scores. You can assume each student has at least 5 test scores.
You may use the JDK or the standard template library. The solution will be evaluated on correctness, runtime complexity (big-O), and adherence to coding best practices. A complete answer will include the following:
Document your assumptions
Explain your approach and how you intend to solve the problem
Provide code comments where applicable
Explain the big-O run time complexity of your solution. Justify your answer.
Identify any additional data structures you used and justify why you used them.
Only provide your best answer to each part of the question.
Use the following skeleton for your solutions.
Java:
- aopencv June 16, 2013 in United Statesclass TestResult { int studentId; String testDate; int testScore; } public class FinalScoreQuestion { Map <Integer, Double> calculateFinalScores (List<TestResult> results) { }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Java Problem Solving Sorting - 2of 2 votes
AnswersCheck if the given binary tree is BST or not.
- aopencv June 14, 2013 in United States| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer Algorithm Data Structures Java - 0of 0 votes
AnswersGiven an integer array, find pairs in an array which sum up to a given number.
- aopencv June 14, 2013 in United States
For example: Array{4,5,1,3,2} and required sum=6 then output should be [1,5] and [2,4].| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer Data Structures Java - 0of 0 votes
AnswersWrite a calculator program in Java that evaluates expressions in a very simple integer expression language. The program takes an input on the command line, computes the result, and prints it to the console. For example:
- Et_e June 11, 2013 in United States
% java calculator.Main “mult(2, 2)”
4
Few more examples:
Input Output
add(1, 2) 3
add(1, mult(2, 3)) 7
mult(add(2, 2), div(9, 3)) 12
let(a, 5, add(a, a)) 10
let(a, 5, let(b, mult(a, 10), add(b, a))) 55
let(a, let(b, 10, add(b, b)), let(b, 20, add(a, b)) 40
A “let” operator for assigning values to variables:
let(<variable name>, <value expression>, <expression where variable is used>)| Report Duplicate | Flag | PURGE
Software Engineer / Developer Java - 0of 0 votes
AnswersWhat are checked exceptions
- meek June 05, 2013 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Java Developer Java - 0of 0 votes
AnswersGiven +ve numbers in an array . Put the even #s to the left of the array and the odd to the right side of the array . Don't use extra array.
- meek June 05, 2013 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Java Developer Coding Java Probability - 0of 0 votes
Answerscode a singleton class
- meek June 05, 2013 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Java Developer Java - 2of 2 votes
AnswersThis question was asked in todays interview's written test. According to me it should go into infinite waiting, but when I run this code on my computer, it safely ends up printing the value. I executed n number of times but still it finishes without without going into infinite waiting.
Can someone explain.
- Anon June 01, 2013 in Indiastatic class Job extends Thread { private int counter; @Override public void run() { synchronized(this) { for(int i = 0; i < 100000; i++) counter++; this.notifyAll(); } } } public static void main(String[] args) throws InterruptedException { Job job = new Job(); job.start(); synchronized(job) { job.wait(); } System.out.println(job.counter); }
| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java - 0of 0 votes
AnswersMerge the given 2 input sorted arrays of numbers into one . The merged array stays sorted .
- meek May 31, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Arrays Java Problem Solving Sorting - 0of 0 votes
AnswersBy default, Hashtable is unordered. Then, how can you retrieve Hashtable elements in the same order as they are put inside???
- amit.grynch May 30, 2013 in United States| Report Duplicate | Flag | PURGE
Adobe Applications Developer Java - 0of 0 votes
Answershow can we measure size of a object in java?
- amit.grynch May 30, 2013 in India| Report Duplicate | Flag | PURGE
Adobe Applications Developer Java - 0of 0 votes
AnswersWrite a function to find a key in Hash map if the value associated to that key is given as input. As a followup, swap key & value assuming that value is not equal to any of the existing keys.
- jyothiprasadb May 21, 2013 in India| Report Duplicate | Flag | PURGE
Oracle Software Engineer in Test Java - 1of 1 vote
AnswersExplain how you would implement a multi-map in Java without using any collections?
- fbrubacher May 17, 2013 in United States| Report Duplicate | Flag | PURGE
Palantir Technology Senior Software Development Engineer Java