On this page
- 1. What is object-oriented programming? What are its properties?
- 2. What's the difference between == and equals()?
- 3. How many types of access modifiers does Java have? What are the characteristics of each?
- 4. What are the characteristics of variables, methods, and classes marked with the final keyword?
- 5. What's the difference between override and overload?
- 6. What's the difference between StringBuilder and StringBuffer in Java?
- 7. What is an interface used for in Java?
- 8. Why isn't Java a fully object-oriented (OOP) language?
- 9. What are wrapper classes in Java? Why do we need them?
- 10. Is Java pass-by-reference or pass-by-value?
- References
Hi everyone 👋. I'm Hung Anh.
Foundational knowledge matters a lot! It doesn't just help you build things faster and more sustainably — it also helps you debug the nasty bugs and design new, creative solutions. That's exactly why, in interviews, employers need to check a candidate's foundational knowledge, whether they're a fresher or a senior engineer.
Here are 10 questions to verify your foundational knowledge of Java.
1. What is object-oriented programming? What are its properties?
Hint:
- Object-oriented programming has 4 properties:
- Encapsulation
- Inheritance
- Abstraction
- Polymorphism
- To make your answer more convincing, explain why each of these properties is needed.
Answer:
Object-Oriented Programming (OOP) is a programming paradigm in which programs are organized around objects. Each object is an instance of a class, and the class defines how objects belonging to it will behave.
The properties of object-oriented programming:
- Encapsulation:
- Encapsulation hides an object's internal information and implementation details, only allowing access through public methods.
- It protects data from unauthorized changes.
- Inheritance:
- Inheritance lets a class reuse the fields and methods of another class.
- It reduces code duplication and increases the flexibility of the source code.
- Abstraction:
- Abstraction hides complex details and focuses only on the aspects of an object that matter.
- It reduces the complexity of the source code and makes it easier to understand.
- Abstraction is expressed through interfaces or abstract classes in Java.
- Polymorphism:
- Polymorphism is a key concept in OOP, where an object or a function can take on multiple forms.
- It's achieved through techniques such as overloading and overriding, upcasting and downcasting.
- Polymorphism makes software more flexible and easier to extend.
2. What's the difference between == and equals()?
Hint:
==: An operator that compares the references of two variables.equals(): A method used to compare the values of two variables.
Answer:
Similarity: both equals() and == in Java are used to compare objects to check for equality, but there's a difference between them.
Differences:
equals()is a method, while==is an operator.- The
==operator compares references (memory addresses), while theequals()method compares content. Simply put,==checks whether both objects point to the same memory location, whileequals()compares the values held inside the objects. Whenever we create an object with thenewoperator, Java allocates a new memory location for it. So we use==to check whether the memory location (or address) of two objects is the same. - If a class doesn't override
equals(), it uses, by default, theequals()implementation of the nearest parent class that did override it.
3. How many types of access modifiers does Java have? What are the characteristics of each?
Hint:
- There are 4 access modifiers:
private,default,protected,public.
Answer:
- Private: The most restrictive scope — fields and methods marked private can only be accessed inside the class that declares them.
- Default: A class, field, or method marked as default can only be accessed by classes within the same package.
- Protected: An extension of default — fields and methods marked protected can be accessed by classes within the same package, as well as by subclasses.
- Public: The widest scope — fields and methods marked public can be accessed from anywhere in the project.

The pangolin is the only mammal covered in scales, which make up 20% of its body weight. When threatened, a pangolin curls up into a tough, armored ball. Tens of thousands of pangolins are poached every year for their meat and scales, which are used in traditional medicine. We should all do our part to help protect this species.
4. What are the characteristics of variables, methods, and classes marked with the final keyword?
Hint:
- Final variable: its value cannot be changed once it has been initialized.
- Final method: this method cannot be overridden by any subclass.
- Final class: a final class cannot be extended by other classes.
Answer:
Variable: once a variable is declared final, its value cannot be changed after it has been assigned once.
final int x = 10;
// x cannot be reassigned
Method: once a method is marked final, it cannot be overridden by subclasses.
class Parent {
final void display() {}
}
class Child extends Parent {
// Error: cannot override a final method
// void display() { }
}
Class: once a class is declared final, no subclass can extend it. Final classes are typically used to prevent a class from being extended or having its behavior changed.
final class FinalClass {}
// Error: cannot extend a final class
// class SubClass extends FinalClass {}
5. What's the difference between override and overload?
Hint:
- Overload: creating two or more methods with the same name but different parameters.
- Override: re-implementing the logic of a parent class's method inside a subclass.
Answer:
Overload:
- Overloading is the process of creating multiple methods with the same name in a class, but with different parameter lists.
- Overloaded methods must share the same name but have different parameter lists — differing in parameter types and/or count.
- Java decides which method to call based on the type and number of arguments passed in.
public class Example {
public void printInfo(String message) {
System.out.println("Message: " + message);
}
public void printInfo(int number) {
System.out.println("Number: " + number);
}
}
Override:
- Overriding happens when a subclass provides a new implementation for a method already defined in its parent class.
- An overriding method must have the same signature (same name, same return type, and same parameter list) as the method in the parent class.
- The purpose of overriding is to provide a new implementation of an existing parent-class method, tailored to the subclass's specific needs.
class Animal {
public void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Dog barks");
}
}
6. What's the difference between StringBuilder and StringBuffer in Java?
Hint:
- Runtime performance.
- Whether it's thread-safe.
Answer:
StringBuilder and StringBuffer are largely the same and expose similar methods, but the key difference is that StringBuffer is synchronized and thread-safe — multiple threads can access the same StringBuffer instance at once. StringBuilder is not synchronized and should be used in single-threaded contexts, or as a local variable inside a method.
Because StringBuilder doesn't need to synchronize, it performs faster than StringBuffer.
7. What is an interface used for in Java?
Hint:
- Multiple inheritance.
- Achieving abstraction.
- Achieving loose coupling.
Answer:
Java doesn't support multiple inheritance because it can lead to the Diamond Problem (when class D inherits from both B and C, which each override A's print() method, D has no way of knowing which parent's print() it should inherit).

Interfaces solve the multiple-inheritance problem. If a class D implements two interfaces B and C that both declare a print() method, class D only ends up with a single implementation of print() — that's one of the properties of interfaces (behavior can change at runtime, depending on the implementation provided).
Using interfaces achieves abstraction, since an interface only contains public abstract methods — any class implementing it must implement all of the interface's methods.
Using interfaces also reduces coupling between classes, letting them operate independently without needing to know each other's implementation.
8. Why isn't Java a fully object-oriented (OOP) language?
Hint:
- Does Java have data types other than object types?
Answer:
Java isn't 100% object-oriented because, besides object data types, it also has 8 primitive data types: char, boolean, byte, short, int, long, float, double.
9. What are wrapper classes in Java? Why do we need them?
Hint:
- How do you use primitive types in places that only accept objects, such as Collections (List, Set, Map, ...)?
- Sometimes you need a value that can be null.
- Sometimes you need to call object methods.
Answer:
Wrapper classes in Java represent Java's 8 primitive data types as object data types. All wrapper classes in Java are immutable and final.
We need wrappers because they:
- Allow the value to be null.
- Can be used in Collections such as List, Map, ... since collections only support object types.
- Let you call methods whose parameters expect an object type.
- Let you use object methods such as
clone(),equals(),hashCode(),toString().
10. Is Java pass-by-reference or pass-by-value?
Hint:
- Inside a method, can you make an input object's reference point to a different object?
Answer:
Java is pass-by-value. There is NO pass-by-reference in Java.
Java has no notion of pointers, so everything is pass-by-value. A method receives a copy of the reference to the object.
Example: Java is pass-by-value, dammit! (Stack Overflow)
public class Main {
public static void main(String[] args) {
Foo f = new Foo("f");
changeReference(f); // It won't change the reference!
modifyReference(f); // It will modify the object that the reference variable "f" refers to!
}
public static void changeReference(Foo a) {
Foo b = new Foo("b");
a = b;
}
public static void modifyReference(Foo c) {
c.setAttribute("c");
}
}
- In
main, we define an instancefof typeFoowith the value"f".
Foo f = new Foo("f");

- Here, a reference named
a(of typeFoo) is declared, initiallynull.
public static void changeReference(Foo a)

- When we call
changeReference,ais assigned a copy of the reference to the object passed in,f.
changeReference(f);

- A reference named
bof typeFoois defined and assigned to a new object with the value"b". When we assigna = b, we're pointinga's reference (notf's) to the object holding the valueb.

- Reference
fnever points to objectb, even afterchangeReferencereturns. WhenmodifyReference(Foo c)is called, a referencecis created and assigned to the object holding the value"f".

Thank you for reading this post. If you have other questions you'd like covered, leave a comment below and I'll add them 👇.
See you in the next posts.
Happy reading! 🍻
References
Related articles
CronJob & Cron Expressions
CronJob is an essential tool that lets developers automate tasks on a recurring schedule. To configure a CronJob correctly, however, you need a solid grasp of the Cron Expression - the expression that defines the schedule for your automated jobs. This article introduces CronJob, explains how to build a Cron Expression, and shares some handy tools for creating cron expressions with ease.

