Java interview questions
Repo nomemory/java-interview-questions, read from GitHub 16 h ago. nomemory has not joined Take My Repo.
nomemory/java-interview-questions is a public repo on GitHub by nomemory. Java interview questions. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It has 70 stars and last changed on 2024-08-22. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
This is a Collection of Computer Science, Java and SQL questions I use for the interviews. Feel free to propose new questions, contributions are open to everyone.
public void swap(int x, int y) { /** code here **/ }
public class PasserBy {
public static void swap(int x, int y) {
int tmp = x;
x = y;
y = tmp;
}
public static void main(String[] args) {
int i = 1, j = 2;
swap(i, j);
System.out.println(i + " " + j);
}
}
final.final class from the Java Standard library ?== and equals() ?public class Ternary {
public static void main(String[] args) {
Integer x = 1987;
Integer y = 1987;
System.out.println(x == y ? "A" : "B");
x = 10;
y = 10;
System.out.println(x == y ? "A" : "B");
}
}
strictfp, native.public abstract class Engineer {
public static String name() {
return "Engineer";
}
public String favorite() {
return "Math and Physics";
}
public static void main(String[] args) {
Engineer e2 = new ElectricalEngineer();
Engineer e3 = new SoftwareEngineer();
System.out.format("%s %s \n", e2.name(), e2.favorite());
System.out.format("%s %s", e3.name(), e3.favorite());
}
}
class ElectricalEngineer extends Engineer {
public static String name() { return "Electrical Engineer" }
public String favorite() { return "Electricity"; }
}
class SoftwareEngineer extends Engineer {
public static String name() { return "Software Engineer"; }
public String favorite() { return "Java"; }
}
static method be overwritten ?public class Circle {
double radius;
double area;
}
public class Constructors {
public static void main(String[] args) {
new Dog();
}
}
class Animal {
public Animal() { System.out.println("1"); }
public Animal(String s) {
this();
System.out.println("2");
}
}
class Dog extends Animal {
public Dog() {
super("3");
System.out.println("4");
}
}
extends or implements another interface ?extends or implements another Java Abstract Class ?default keyword (Java 8 onwards).default keyword are there any reasons to use Abstract Classes instead of Interfaces ?List<Integer> (don't use for/do/while loops).| List | Set | Map<K,V> | Queue |
|---|---|---|---|
impossible to say:public class Maps {
public static void main(String[] args) {
Map<String, Integer> map1, map2, map3;
map1 = Map.of(
"A", 0,
"D", 1,
"B", 2,
"C", 3
);
map2 = new LinkedHashMap<>(map1);
map3 = new TreeMap<>(map1);
System.out.println(map2);
System.out.println(map3);
}
}
3):public class Sets {
public static void main(String[] args) {
Set<CustomData> set = new HashSet<>();
CustomData customData = new CustomData();
set.add(customData);
set.add(customData);
set.add(new CustomData());
set.add(new CustomData());
System.out.println(set.size());
}
}
class CustomData {
@Override
public int hashCode() {
return 0;
}
}
null as an element ?Iterator and ListIterator ?class Test {
public static void main(String[] args) {
List<String> list = new LinkedList<>();
list.add("A");
list.add("C");
list.add("D");
Iterator<String> it = list.iterator();
System.out.println(it.next());
list.add(1, "B");
System.out.println(it.next());
System.out.println(it.next());
System.out.println(it.next());
}
}
public class Lambada {
private String name = "Agent Smith";
public void doLambda() {
Doer doer = () -> {
System.out.println(this.name);
};
doer.doAction();
}
public void doAnonymous() {
Doer doer = new Doer() {
@Override
public void doAction() {
System.out.println(this.name);
}
};
doer.doAction();
}
public static void main(String[] args) {
Lambada lambada = new Lambada();
lambada.doLambda();
lambada.doAnonymous();
}
}
@FunctionalInterface
interface Doer {
void doAction();
}
filter() method write a method that returns only the positive numbers from a List<Integer>.parallelStream() ? How is it different from a standard stream() ?List<Integer> using the reduce() method.List<Integer> using the reduce() method.class Test {
public static void main(String[] args) {
final List<String> l = new LinkedList<>();
l.add("A");
l.add("B");
l.add("C");
l.stream().forEach(e -> {
l.add("Z");
System.out.println(e);
});
}
}
++ operator thread-safe ?thread.join() working ?class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Void> cf1 = CompletableFuture.runAsync(() -> {
System.out.println("B");
});
CompletableFuture<Void> cf2 = CompletableFuture.runAsync(() -> {
System.out.println("A");
});
cf1.get();
cf2.get();
}
}
singleton, prototype, request, session, global session.@Component, @Controller, @Repository, @Service.@Autowired, @Qualifier, @Required.@Async annotations functions.Advantages: Improved Scalability, Fault Isolation, Localised Complexity, Increased Agility, Simplified Debugging and Maintenance, Smaller Development Teams, etc.
Disadvantages: Complexity (e.g.: Dependencies), Requires accurate pre-planning, End-to-end testing is difficult, Complex deployment procedures, etc.
@HystrixCommand annotations works in a Spring Cloud implementation?| Operation | HTTP VERB | ENDPOINT |
|---|---|---|
| Add a book | ||
| Remove a book | ||
| List books with pagination | ||
| Edit a book | ||
| Get info for a book |
Given the following SQL table employees:
| id | full_name | mng_id |
|---|---|---|
| 100 | Patrick Read | 101 |
| 101 | Bradley Hayes | null |
| 102 | Kieran Bennett | 101 |
| 103 | George Barnes | 101 |
| 104 | Alex Griffiths | 102 |
| 105 | Issac Jacobs | 102 |
| 106 | Will Mack | 104 |
Write an SQL query that returns the following result:
| id | full_name | mng_full_name |
|---|---|---|
| 100 | Patrick Read | Bradley Hayes |
| ... | ............ | ............. |
Write an SQL query that returns one row containing the manager with the most direct subalterns.
Input examples: "abcsadjnii"
Given a list of integers LIST = [1,4,3,3,2,5,1,2,5,7,7, ...] with size N.
We know LIST contains only duplicated numbers (numbers that appear twice) except ONE integer which is called The Solitary Integer.
Write an efficient algorithm that will determine this integer ?
Can you solve the exercise in O(N) ?
Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly, because it is a pangram. (Pangrams are sentences constructed by using every letter of the alphabet at least once.) After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams. Given a sentence s, tell Roy if it is a pangram or not.
Input Format Input consists o a string s. Example:
We promptly judged antique ivory buckles for the next prize
Output Format Output a line containing “pangram” if s is pangram, otherwise print “not pangram”. Example:
pangram
Given a sequence consisting of parentheses, determine whether the expression is balanced. A sequence of parentheses is balanced if every open parentheses can be paired uniquely with a closed parentheses that occurs after the former. Also, the interval between them must be balanced. You will be given three types of parentheses: (, {, and [.
{[()]} - This is a balanced parentheses.
{[(])} - This is not a balanced parentheses.
Example:
Input
3
{[()]}
{[(])}
{{[[(())]]}}
Ouput
YES
NO
YES
nomemory/java-interview-questions is a public repo on GitHub by nomemory. Java interview questions.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2024-08-22. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
A LC3 virtual machine implementation in a few lines of C code
A library that extends the Java Bean Validation with additional @Annotations.
nml is a "simple" matrix/numerical analysis library written in pure C. The scope of the library is to highlight various algorithm implementations related to matrices. Code readability was a major concern.