1. What is Java?
Ans:
Java is an object-oriented, high-level programming language that's used to make applications that can run on any device with a Java Virtual Machine (JVM). It's platform-independent, secure and widely used for web, desktop, and mobile applications.
2. What are Java's primary features?
Ans:
- Object-Oriented
- Simple and Secure
- Robust and Portable
- Multithreaded and High Performance
- Automatic Garbage Collection
3. Describe Java's object-oriented programming concept.
Ans:
Object-Oriented Programming (OOP) in Java is based on concepts like Class, Object, Inheritance, Polymorphism, Encapsulation, and Abstraction. Java uses these to structure programs into reusable, organized pieces of code.
4. What are the different access modifiers in Java?
Ans:
- public – Accessible from anywhere
- private – Accessible only within the class
- protected – Available inside the same package and subclasses
- default (without a modifier) - available in the same package
5. What distinguishes an abstract class from an interface?
Ans:
- Only abstract methods are allowed in interfaces (before Java 8) and constants; it supports multiple inheritance.
- Both abstract and concrete methods can be included in an abstract class allows constructors and instance variables.
6. Explain the Java exception handling mechanism.
Ans:
- Java uses try-catch-finally blocks to handle exceptions.
- There is code in try that could result in an exception
- Catch deals with the exception.
finally contains code that always executes, even if an exception is thrown
7. What is the difference between checked and unchecked exceptions?
Ans:
- Checked exceptions are checked at compile time (e.g., IOException)
- Unchecked exceptions are checked at runtime (e.g., NullPointerException)
8. What is the Java Collections Framework?
Ans:
It’s a set of classes and interfaces (like List, Set, Map) that provide data structures and algorithms to store, retrieve and manipulate data efficiently.
9. What is a Java Stream?
Ans:
A Stream in Java is used to process collections of data in a functional style. It permits functions such as element reduction, mapping and filtering without modifying the source.
10. Describe Java trash collection concept.
Ans:
Garbage Collection is Java’s automatic memory management process. It frees up memory by removing objects that are no longer used or referenced by the program.