• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

? 40 Java Interview Questions Every Developer Should Master

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Whether you're a fresher trying to land your first job or an experienced developer aiming for a senior role, knowing the right Java interview questions — and how to answer them well — can make all the difference.

Below are 40 essential Java questions with detailed answers that cover everything from core concepts to advanced topics.

? 1. What is the difference between JDK, JRE, and JVM?


Answer:

  • JVM (Java Virtual Machine): Runs Java bytecode. It's platform-dependent but provides platform independence at the code level.
  • JRE (Java Runtime Environment): Contains the JVM + libraries for running Java applications.
  • JDK (Java Development Kit): JRE + development tools (compiler, debugger). Used to write and compile Java code.
? 2. What are the key features of Java?


Answer:

  • Object-Oriented
  • Platform Independent
  • Robust (Garbage Collection, Exception Handling)
  • Secure (Bytecode verifier, no pointers)
  • Multithreaded
  • Portable
  • High Performance (JIT Compiler)
? 3. What is the difference between == and .equals()?


Answer:

  • == compares references (memory addresses).
  • .equals() compares values/content. Override .equals() to customize this behavior in your class.
? 4. What are the data types in Java?


Answer:
Java has:

  • Primitive types: byte, short, int, long, float, double, char, boolean
  • Reference types: objects, arrays, strings
? 5. What is autoboxing and unboxing?


Answer:

  • Autoboxing: Primitive to wrapper class conversion (e.g., int → Integer)
  • Unboxing: Wrapper to primitive (e.g., Integer → int)
? 6. What is the difference between ArrayList and LinkedList?


Answer:

  • ArrayList: Fast access, slow insert/remove
  • LinkedList: Slow access, fast insert/remove at head/tail
? 7. What is the difference between HashMap and Hashtable?


Answer:

  • HashMap: Not synchronized, allows one null key
  • Hashtable: Thread-safe (synchronized), no null keys/values
? 8. What is a constructor? Can it be inherited?


Answer:
A constructor is a special method to initialize objects. Constructors are not inherited, but a subclass can call the parent constructor using super().

? 9. What is the use of final keyword?


Answer:

  • final variable: Constant value
  • final method: Cannot be overridden
  • final class: Cannot be extended
? 10. What is method overloading and overriding?


Answer:

  • Overloading: Same method name, different parameters (compile-time polymorphism)
  • Overriding: Subclass provides a specific implementation of a parent method (run-time polymorphism)
? 11. What is abstraction in Java?


Answer:
Abstraction hides implementation details. Achieved using:

  • Abstract classes
  • Interfaces
? 12. What is the difference between an abstract class and an interface?


Answer:

  • Abstract class: Can have constructors, fields, method implementations
  • Interface: Only method signatures (Java 8+ allows default/static methods)
? 13. What is encapsulation?


Answer:
Encapsulation hides internal object state using private fields and public getters/setters. It protects data integrity.

? 14. What is inheritance?


Answer:
Inheritance allows a class (child) to inherit properties/methods from another (parent). Promotes reusability.

? 15. What is polymorphism?


Answer:
Polymorphism allows the same interface to behave differently:

  • Compile-time: Method overloading
  • Run-time: Method overriding
? 16. What are access modifiers in Java?


Answer:

  • private: Only within class
  • default (no modifier): Package-level access
  • protected: Package + subclass access
  • public: Accessible everywhere
? 17. Difference between static and non-static methods?


Answer:

  • static: Belongs to class, can’t access non-static members directly
  • non-static: Belongs to object, can access static members
? 18. What is a static block?


Answer:
A static block initializes static data. Executes once when the class is loaded.

? 19. Can you override static methods?


Answer:
No. Static methods belong to the class and not the instance, so they can’t be overridden. They can be hidden, though.

? 20. What is the purpose of this keyword?


Answer:
this refers to the current object instance. Commonly used to avoid naming conflicts and pass current object.

? 21. What is garbage collection in Java?


Answer:
Automatic memory management. Unused objects are cleaned up by the Garbage Collector (GC).

? 22. How do you force garbage collection?


Answer:
You can suggest GC using System.gc(), but the JVM is not guaranteed to perform it immediately.

? 23. What are exceptions in Java?


Answer:
Unexpected events that disrupt normal flow. Java has:

  • Checked Exceptions: Must handle (e.g., IOException)
  • Unchecked Exceptions: Runtime issues (e.g., NullPointerException)
? 24. What is the difference between throw and throws?


Answer:

  • throw: Used to throw an exception
  • throws: Declares that a method may throw an exception
? 25. What is try-with-resources?


Answer:
Introduced in Java 7. Ensures automatic closing of resources like FileReader, BufferedReader, etc.


try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
// read file
}
? 26. What is multithreading?


Answer:
Multithreading allows concurrent execution of two or more threads. Improves performance for I/O-heavy operations.

? 27. What is the difference between Runnable and Thread?


Answer:

  • Runnable: Interface
  • Thread: Class that implements Runnable Using Runnable is more flexible (can extend other classes)
? 28. What is synchronization?


Answer:
Synchronization controls access to shared resources to prevent thread interference or memory consistency errors.

? 29. What is a deadlock?


Answer:
Occurs when two or more threads are waiting on each other to release locks. They get stuck indefinitely.

? 30. What is a lambda expression?


Answer:
Introduced in Java 8. It enables writing anonymous methods concisely.


(a, b) -> a + b
? 31. What are functional interfaces?


Answer:
Interfaces with only one abstract method. Example: Runnable, Callable, Comparator, Function

? 32. What is the Stream API?


Answer:
Introduced in Java 8. Used to process collections in a functional style (filter, map, reduce, etc.).

? 33. What is Optional in Java 8?


Answer:
A container that may or may not hold a non-null value. Helps avoid NullPointerException.


Optional<String> name = Optional.ofNullable("John");
? 34. What is the difference between Comparable and Comparator?


Answer:

  • Comparable: Natural ordering (compareTo())
  • Comparator: Custom ordering (compare())
? 35. What is the transient keyword?


Answer:
Marks a variable not to be serialized. Used when saving object state to file.

? 36. What is the volatile keyword?


Answer:
Ensures visibility of changes to variables across threads. Prevents caching by threads.

? 37. What is the difference between stack and heap memory?


Answer:

  • Stack: Stores method calls and local variables
  • Heap: Stores objects and class instances
? 38. What are annotations?


Answer:
Metadata that provide information to the compiler or runtime (e.g., @Override, @Deprecated, @FunctionalInterface)

? 39. What are design patterns in Java?


Answer:
Reusable solutions to common software problems. Examples:

  • Singleton
  • Factory
  • Builder
  • Observer
  • Strategy
? 40. What’s new in Java 17+?


Answer:

  • Sealed classes
  • Pattern matching for switch
  • Records (data classes)
  • Strong encapsulation of internal APIs

? Final Tip: Don’t just memorize answers. Understand the why behind each concept and use hands-on examples to reinforce your knowledge.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу