Java Programmer Interview Questions | Glassdoor

Java Programmer Interview Questions

40

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

5 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.

4 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); } }

1 Answer

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(); } }

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

1. Initially Lot of those cliché questions like "what was the most challenging project?, why it was challenging? what was your role? what particular task made it challenging? Why not tried some other way? What did you learn from that experience?" 2. The HR person asked me lot of critical thinking questions. lot of them were on internet... :) 3. Asked why do I like consulting, and why not try for a permanent job at some big company ?

1 Answer

Whats the subject you don't like in your course and why

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

110 of 40 Interview Questions