Java Interview Questions | Glassdoor

Java Interview Questions


interview questions shared by candidates

Java Interview Questions

Sort: RelevancePopular Date

Find the second largest element in a Binary Search Tree

16 Answers

find the right most element. If this is a right node with no children, return its parent. if this is not, return the largest element of its left child.

One addition is the situation where the tree has no right branch (root is largest). In this special case, it does not have a parent. So it's better to keep track of parent and current pointers, if different, the original method by the candidate works well, if the same (which means the root situation), find the largest of its left branch.

if (root == null || (!root.hasRightChild() ) { return null;} else return findSecondGreatest(root, root.getValue()); value findSecondGreatest(Node curr, value oldValue) { if(curr.hasRightChild()) { return (findSecondGreatest( curr.getRightChild(), curr.value)); } else return oldValue; }

What is a volatile variable, and why would you use it?

2 Answers

What is the most used Java class?

1 Answer

In a Unix environment what are the top 3-5 considerations for performance monitoring a Java application that has access to a local Oracle instance (located on the same server). Please be as specific as possible (i.e. commands, locations, etc.)

1 Answer

List all anagrams in a file. Assumptions: case-insensitive, a-z characters only, one word per line. For example, if the file contains dog, cat, ddd, goo, act, god -- output dog, god, act, cat

10 Answers

Write a function in Java that will take a sorted array of ints, possibly with duplicates, and compact the array removing all the duplicate numbers. That is, if the contains the numbers - 1, 3, 7, 7, 8, 9, 9, 9, 10, then when the function returns, the contents should be - 1, 3, 7, 8, 9, 10. Be sure your answer is as efficient as possible. Describe the efficiency of your algorithm using big O notation.

5 Answers

Java Code to implement 5 places (code)

6 Answers

public class WhichReturns{ public String whichReturns(){ try{ return "1"; }finally{ return "2"; } public static void main(String argv){ System.out.println("Return val: " + WhichReturns.whichReturns()); } }

4 Answers

Diff b/w var1 == var2 and var1.equals(var2) Which method needs to be implemented along with equals()?

4 Answers

Write a code to find out if two string words are anagrams

4 Answers
110 of 199 Interview Questions