Java Programmer Interview Questions | Glassdoor

Java Programmer Interview Questions

45

Java programmer interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Assume there is a method provided getNextperson() which gives Person objects which have comparable interface implemented, now read from a file records and sort it and give first 1000 records, write code on the paper

7 Answers

maybe use tree data structure

tree data structure ? i hope u meant to say "TreeSet"; but the question doesnt say that getNextPerson() will be unique. So let us not bank on treeSet. So just add them on to a arrayList and do a Collections.sort(arrayList);

The question is actually quite simple since you were given that Comparable interface is already implemented (eg, public int compareTo(Object o) method is overridden in Person object). First step, 'read from a file all records' and store each Person object returned by getNextPerson() in List records = new ArrayList(). Next step, call Collections.sort(records) to sort (by criteria specified in compareTo() method, such as Last and First name, or any other meaningful parameter). Final step, 'give first 1000 records' -- either by iterating over first 1000 (checking size() >= 1000) or by returning the list consisting of only 1000 records (either copy into a new list with size 1000 or by using removeRange method in ArrayList.

Write code to return a sorted array of int, when passed in 2 sorted array of int to the method.

5 Answers

what is the output public class Barclays { static class A{ A(){ f(); } public void f(){ System.out.println("A ctor"); } } static class B extends A{ B(){ f(); } public void f(){ System.out.println("B ctor"); } } public static void main(String[] args) { B b = new B(); b.f(); A a = new A(); a.f(); } }

3 Answers

package com.interview; public class Threading { int counter; class Mythread extends Thread{ @Override public void run(){ for(int i=0; i < 10000; i++) counter++; System.out.println("run = " + counter); } } public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub Threading a = new Threading(); Mythread t1 = a.new Mythread(); t1.start(); t1.join(); System.out.println("" + a.counter); } }

2 Answers

They asked the typical java developer questions. Because I have been a professional programmer with outstanding major firms for years, programming in java since 2000, I was able to answer each question very well.

1 Answer

Describe a time that you went to a superior for assistance, and did not receive the assistance you were expecting.

You were 2 mins late right?

1 Answer

n-ary tree traversal for coding with slight variations Past work experience Agile/Scrum process

What technologies are you familiar with?

1 Answer
110 of 45 Interview Questions