Java foundamental: 25 flashcards
All 25 flashcards from this kit, free and with no sign-up.
1. What is the main difference between `int` and `Integer` in Java?
Show the answer
`int` is a primitive type; `Integer` is a wrapper class that allows `null` and provides utility methods.
2. What does the `final` keyword do when applied to a variable?
Show the answer
It makes the variable a constant — its value cannot be changed after initialization.
3. What is the purpose of the `static` keyword in Java?
Show the answer
It declares a member (variable or method) that belongs to the class itself, not to any instance.
4. What is the short way to write a for loop that iterates over an array or collection?
Show the answer
The enhanced for-each loop: `for (Type item : collection) { ... }`
5. What is autoboxing in Java?
Show the answer
Automatic conversion of a primitive type to its corresponding wrapper class (e.g., `int` to `Integer`).
6. What is the difference between `==` and `.equals()` for comparing objects?
Show the answer
`==` compares references (memory addresses); `.equals()` compares the actual content (if overridden).
7. What does the `break` statement do inside a loop?
Show the answer
It immediately terminates the loop and exits to the next statement after the loop.
8. What is the default value of a `boolean` field in a Java class?
Show the answer
`false`
9. What is the short way to declare and initialize an array in one line?
Show the answer
`int[] arr = {1, 2, 3};` (array initializer syntax).
10. What is the purpose of the `this` keyword in Java?
Show the answer
It refers to the current object instance, often used to distinguish instance variables from parameters.
11. What does the `super` keyword do?
Show the answer
It refers to the immediate parent class object, used to access parent constructors, methods, or fields.
12. What is the short way to create an `ArrayList` of strings and add an element?
Show the answer
`ArrayList<String> list = new ArrayList<>(); list.add("hello");`
13. What is the difference between `public` and `private` access modifiers?
Show the answer
`public` allows access from any class; `private` restricts access to within the same class only.
14. What is the short way to write an if-else statement that returns a value?
Show the answer
The ternary operator: `result = (condition) ? valueIfTrue : valueIfFalse;`
15. What is the purpose of the `@Override` annotation?
Show the answer
It indicates that a method is intended to override a method in a superclass; the compiler checks for correctness.
16. What is the short way to iterate over a `List` using a lambda expression?
Show the answer
`list.forEach(item -> System.out.println(item));`
17. What is the difference between `StringBuilder` and `StringBuffer`?
Show the answer
`StringBuilder` is faster but not thread-safe; `StringBuffer` is thread-safe but slower.
18. What are the eight primitive data types in Java?
Show the answer
byte, short, int, long, float, double, char, boolean
19. What is the entry point of a Java application?
Show the answer
The main method: public static void main(String[] args)
20. How does Java achieve platform independence?
Show the answer
Java source code is compiled to bytecode, which runs on the Java Virtual Machine (JVM), making it platform-independent.
21. What is the difference between a primitive variable and a reference variable in terms of memory storage?
Show the answer
A primitive variable stores the actual value directly in memory, while a reference variable stores the memory address of an object.
22. What does the `default` access modifier mean in Java?
Show the answer
It means the member is accessible only within the same package (package-private).
23. What is the purpose of the `protected` access modifier?
Show the answer
It allows access within the same package and by subclasses (even if they are in different packages).
24. What is encapsulation in Java?
Show the answer
Encapsulation is the practice of hiding internal data and methods using access modifiers (e.g., private) and providing controlled access via public getters/setters.
25. What is the JVM?
Show the answer
The Java Virtual Machine (JVM) is an abstract machine that executes Java bytecode, providing runtime environment and platform independence.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages