© Copyright 2015 - 2024
Privacy PolicyWebsite Terms1
Name a few types of Collections in Java.
2
What is the difference between fail-safe
and fail-fast
iterators?
3
Which Java type would you use if you want to store something per Thread?
4
What is a TreeSet
and when would you use it?
5
What is the output of the following code snippet, and why?
System.out.println("asd"=="asd");
System.out.println(new String("asd")==new String("asd"));
System.out.println(new String("asd").equals(new String("asd")));
System.out.println("asd"=="asd");
System.out.println(new String("asd")==new String("asd"));
System.out.println(new String("asd").equals(new String("asd")));
6
Each of the two examples contains 2 cases of string concatenation, which way of string concatenation is better in each example, and why?
Example 1
/* case 1.1 */ String a = s + s + s;
/* case 1.2 */ String a1 = new StringBuilder(s).append(s).append(s).toString();
Example 2
String b = "";
StringBuilder b1 = new StringBuilder();
for(int i = 0; i < 20; i++) {
/* case 2.1 */ b += s;/* case 2.2 */ b1.append(s);}
b1.toString();
7
What does the synchronized
keyword mean and where would you use it?
8
What's the difference between StringBuilder
and StringBuffer
?
9
What's the synchronized version of a HashMap
?
10
What's the difference between a HashSet
and a LinkedHashSet
?
11
What is a deadlock?
12
What are generics in Java?
13
What is the problem with the following example and does it compile?
class Animal<T> {T animal;Integer age;public Animal(T animal, Integer age) {this.animal = animal;this.age = age;}
}
new Animal(123, 123);
class Animal<T> {T animal;Integer age;public Animal(T animal, Integer age) {this.animal = animal;this.age = age;}
}
new Animal(123, 123);
14
Why are exceptions expensive in Java?
15
What are default methods?
16
What types of Exceptions exist in Java (and what is the difference)? Name few common Exceptions of each type.
17
Given the following example code, which overrides are valid and which one aren't (with explanation)?
private abstract static class C1 {public abstract void m1() throws Exception;public abstract void m2() throws IOException;public abstract void m3() throws Exception;}
private static class C2 extends C1 {@Overridepublic void m1() throws IOException {}@Overridepublic void m2() throws Exception {}@Overridepublic void m3() {}}
private abstract static class C1 {public abstract void m1() throws Exception;public abstract void m2() throws IOException;public abstract void m3() throws Exception;}
private static class C2 extends C1 {@Overridepublic void m1() throws IOException {}@Overridepublic void m2() throws Exception {}@Overridepublic void m3() {}}
18
What is the difference between an Application server and servlet container?
19
What is JDBC?
20
What is JPA and how is it different from JDBC?
21
What are static methods and fields? What is wrong with using a static method in a class like new Class().someStaticMethod()
?
22
Why is Java said to be 'write once, run everywhere'?
23
What is the parent class that every other class extends from?
24
Primitive vs Object types?
25
What is Auto-boxing and Unboxing, and does it impact performance?
26
Identify the Autoboxing and the Unboxing in the following example:
List<Long> list = new ArrayList<>();
list.add(1L);
long l = list.get(0);
List<Long> list = new ArrayList<>();
list.add(1L);
long l = list.get(0);
27
Where would you use LinkedList
and where an ArrayList
?
28
What does the following code usually output? And why usually?
System.out.println(3 == 3);
System.out.println(15000 == 15000);
System.out.println((Integer)127 == (Integer)127);
System.out.println((Integer)128 == (Integer)128);
System.out.println(3 == 3);
System.out.println(15000 == 15000);
System.out.println((Integer)127 == (Integer)127);
System.out.println((Integer)128 == (Integer)128);
29
What are Reflections?
Join 5K+ tech leaders
Stay up to date with Software Engineering, Distributed Teams, Agile Talent, and Future of Work content
No spam. Just great articles & insights
Thank you!
You have successfully subscribed.
Ready to start?
Get in touch or schedule a call.