1. How are Java and C++ different from each other?
Ans:
Java works on any device that has a Java program, while C++ works directly on the system it's written for. Java manages memory by itself, but in C++, the programmer has to take care of memory manually.
2. What does encapsulation mean in Java?
Ans:
Encapsulation means keeping the details of how something works hidden. In Java, this is done by putting data and actions together and only letting outside parts see what they need to.
3. What is inheritance in Java? Can you give a simple idea?
Ans:
Inheritance means one thing can get features from another. For example, if a general class is “Vehicle,” a “Car” can inherit from it and use its basic features, like moving or stopping.
4. How does Java take care of memory?
Ans:
Java automatically removes things from memory when they're no longer needed. This helps the program run smoothly without the developer needing to clear memory manually.
5. What does polymorphism mean in Java?
Ans:
Polymorphism means that one action can behave in different ways. In Java, it allows different objects to respond to the same instruction in their own way.
6. Why is the “this” word used in Java?
Ans:
The word “this” is used when Java needs to make it clear that it’s talking about the current object. It's like saying “me” when talking about yourself.
7. How does Java deal with errors or problems during the program?
Ans:
Java has a way to catch and manage errors so the program doesn't crash suddenly. It lets the programmer handle the problem and keep the program running smoothly.
8. What’s the difference between throw and throws in Java?
Ans:
“Throw” is used when you actually cause a problem to be noticed in the program. “Throws” is used to say that a method might cause a problem and the programmer should be ready for it.
9. What is synchronization in Java?
Ans:
Synchronization is like putting a lock on a shared item so only one person can use it at a time. It assists in preventing errors when several jobs attempt to alter the same thing independently.
10. Why is HashSet used in Java?
Ans:
Items are stored using a hash set which prevents repeating the iteams. Its similar to the basket where every item is different and the arrangement doesn't matter.