1. What is Java?
Ans:
Java is a high-level, object-oriented programming language developed to build applications that can run on any device with a Java Virtual Machine (JVM). It offers platform independence, security, and is widely utilized for web, desktop, and mobile development.
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:
The Java Collections Framework is a group of classes and interfaces like List, Set, and Map that provide data structures and algorithms to efficiently handle, access, and manipulate collections of data.
9. What is a Java Stream?
Ans:
A Stream in Java enables functional-style operations on data collections, allowing actions such as filtering, mapping, and reducing elements without modifying the original collection.
10. Describe Java trash collection concept.
Ans:
Garbage collection in Java is an automatic memory management process that frees memory by deleting objects no longer referenced or used by the application.