Java Questions

Java Memory Notes

























1. What are Java's primitive data types?


Primitive types include byte, short, int, long, float, double, char, and boolean.



2. What is method overloading in Java?


Method overloading is defining multiple methods with the same name but different parameters.



3. What is method overriding in Java?


Method overriding occurs when a subclass provides a specific implementation of a method from its superclass.







4. What is the final keyword in Java?


The final keyword is used to define constants, prevent method overriding, or inheritance.



5. What is a static method in Java?


A static method belongs to the class rather than an instance of the class.



6. What is Java's exception hierarchy?


The hierarchy starts with Throwable, which has two branches: Error and Exception.







7. How do you handle exceptions in Java?


Use try, catch, finally, and throw to handle exceptions.



8. What is the difference between throw and throws? throw is used to explicitly throw an exception; throws declares exceptions in a method signature.


9. What are Java's control statements?


Control statements include if, else, switch, for, while, and do-while.







10. What is a Java thread? A thread is a lightweight process in Java for performing concurrent tasks.


11. What is the difference between Runnable and Thread?


Runnable is an interface; Thread is a class. Implementing Runnable is preferred for better flexibility.



12. What is synchronization in Java?


Synchronization ensures that only one thread accesses critical sections at a time.







13. What are Java's memory areas?


Memory areas include Heap, Stack, Code, and Method Area.



14. What is garbage collection in Java?


Garbage collection is the process of reclaiming unused memory automatically.



15. What are Java's collections?


Collections are frameworks like ArrayList, HashMap, and HashSet for managing data structures.







16. What is a HashMap in Java?


A HashMap is a collection that maps keys to values using hashing.



17. What is the difference between HashMap and Hashtable?


HashMap is unsynchronized and allows null keys; Hashtable is synchronized and doesn't allow null keys.



18. What is the transient keyword in Java?


The transient keyword prevents serialization of certain fields.







19. What is the volatile keyword in Java?


volatile ensures that changes to a variable are visible to all threads.



20. What are Java's functional interfaces?


Functional interfaces have a single abstract method and are used in lambda expressions.



21. What is the Stream API in Java?


The Stream API allows processing sequences of data with functional programming techniques.







22. What is the difference between Comparable and Comparator?


Comparable is used for natural ordering; Comparator is used for custom ordering.



23. What is reflection in Java?


Reflection is the ability to inspect and modify classes, methods, and fields at runtime.



24. What is the purpose of the super keyword?


super is used to refer to the immediate parent class.







25. What is polymorphism in Java?


Polymorphism allows methods to perform differently based on the object that calls them.



List Memory Pages
Share Via Whastapp/Facebook
Share to Your Friends

Share this protal to share friends and complete unlimited tests here. You can also make friends on our protal also start mutual competition tests with your firends easily.

Share to Facebook Share to WhatsApp Promote & Earn