Here are 50 common interview questions and answers for Java fresher:

 Sure! Here are 50 common interview questions and answers for Java fresher:

1. What is Java?

Java is a high-level, object-oriented programming language used to develop a wide range of applications.


2. What are the main features of Java?

Java is platform-independent, supports multithreading, has automatic memory management (garbage collection), and provides a rich set of APIs.


3. What is the difference between JDK and JRE?

JDK (Java Development Kit) is a software development environment that includes tools for developing, debugging, and compiling Java applications. JRE (Java Runtime Environment) is required to run Java applications.


4. What is the difference between a class and an object?

A class is a blueprint or template for creating objects, while an object is an instance of a class.


5. What is the difference between a compiler and an interpreter?

A compiler converts the entire source code into machine code before execution, while an interpreter converts and executes the code line by line.


6. What is the main method in Java?

The main method is the entry point of a Java program and is used to start the execution of the program.


7. What is a constructor?

A constructor is a special method that is used to initialize objects. It has the same name as the class and is called when an object is created.


8. What is method overloading?

Method overloading allows multiple methods in a class to have the same name but different parameters.


9. What is method overriding?

Method overriding occurs when a subclass provides its own implementation of a method that is already defined in its superclass.


10. What are access modifiers in Java?

Access modifiers (public, private, protected) control the visibility and accessibility of classes, methods, and variables.


11. What is inheritance in Java?

Inheritance is a mechanism in Java where one class inherits the properties and methods of another class.


12. What is the difference between an abstract class and an interface?

An abstract class can have both abstract and non-abstract methods, while an interface can only have abstract methods. A class can implement multiple interfaces, but it can only inherit from a single abstract class.


13. What is the difference between checked and unchecked exceptions?

Checked exceptions are checked at compile-time and must be either handled using try-catch blocks or declared in the method signature. Unchecked exceptions are not checked at compile-time.


14. What is the difference between String, StringBuilder, and StringBuffer?

String is immutable, while StringBuilder and StringBuffer are mutable. StringBuilder is not thread-safe, while StringBuffer is thread-safe.


15. What is the difference between == and equals() method?

The == operator compares object references, while the equals() method compares the content of objects.


16. What is a static method and a static variable?

A static method belongs to the class and can be called without creating an instance of the class. A static variable is shared among all instances of the class.


17. What is a package in Java?

A package is a way to organize classes into a hierarchical structure to avoid naming conflicts.


18. What are wrapper classes in Java?

Wrapper classes provide a way to use primitive data types as objects. They provide utility methods and are used in situations where objects are required.


19. What is the final keyword in Java?

The final keyword can be applied to a class, method, or variable. It indicates that the class cannot be subclassed, a method cannot be overridden, or a variable cannot be modified.


20. What is the difference between a stack and a heap?

The stack is used for static memory allocation, including method calls and local variables, while the heap is used for dynamic memory allocation, including objects.


21. What is polymorphism?

Polymorphism is the ability of an object to take on many forms. It allows objects of different classes to be treated as objects of a common superclass.


22. What is a thread in Java?

A thread is a lightweight subprocess that can run concurrently with other threads. It allows multiple tasks to be executed concurrently in a single program.


23. What is synchronization in Java?

Synchronization is the process of controlling the access of multiple threads to shared resources to prevent data inconsistency and thread interference.


24. What are the different types of loops in Java?

Java supports three types of loops: for loop, while loop, and do-while loop.


25. What is a lambda expression?

A lambda expression is an anonymous function that can be used to implement functional interfaces. It simplifies the syntax of writing functional interfaces.


26. What is the difference between stack and queue?

Stack follows the Last-In-First-Out (LIFO) principle, while a queue follows the First-In-First-Out (FIFO) principle.


27. What is the difference between an ArrayList and a LinkedList?

ArrayList uses a dynamic array to store elements, while LinkedList uses a doubly linked list. ArrayList provides fast random access, while LinkedList provides fast insertion and deletion.


28. What is the difference between break and continue statements?

The break statement is used to terminate a loop or switch statement, while the continue statement is used to skip the remaining code in a loop and continue with the next iteration.


29. What is the purpose of the "final" keyword for variables?

The final keyword for variables makes them unmodifiable (constants) once assigned a value.


30. What is the difference between a shallow copy and a deep copy?

A shallow copy creates a new object but references the same memory location, while a deep copy creates a new object with its own memory space.


31. What is the Java Virtual Machine (JVM)?

The JVM is an abstract machine that provides a runtime environment for executing Java bytecode.


32. What is a garbage collector?

A garbage collector is responsible for automatically reclaiming memory occupied by objects that are no longer in use.


33. What is the purpose of the "this" keyword in Java?

The "this" keyword refers to the current instance of a class and is used to differentiate between instance variables and parameters with the same name.


34. What is the difference between a checked and an unchecked exception?

A checked exception must be declared in the method signature or handled using try-catch blocks, while an unchecked exception does not require such handling.


35. What is the purpose of the finalize() method?

The finalize() method is called by the garbage collector before an object is destroyed. It allows the object to perform cleanup operations before being reclaimed.


36. What is the Java API?

The Java API (Application Programming Interface) is a library of prewritten classes and interfaces that provide ready-to-use functionality for Java programs.


37. What is the difference between an applet and an application?

An applet is a small Java program that runs within a web browser, while an application is a standalone program that runs on a computer.


38. What is the difference between a constructor and a method?

A constructor is a special method used to initialize objects, while a method is a regular member function that performs a specific task.


39. What is a reflection in Java?

Reflection is a feature that allows a Java program to examine or modify the structure and behavior of classes, methods, and variables at runtime.


40. How are exceptions handled in Java?

Exceptions are handled using try-catch blocks. The try block contains the code that might throw an exception, and the catch block handles the exception if it occurs.


41. What is the purpose of the "super" keyword in Java?

The "super" keyword is used to refer to the superclass or parent class. It is used to call superclass methods, access superclass variables, and invoke superclass constructors.


42. What is the difference between static and instance variables?

Static variables are associated with the class and shared among all instances, while instance variables are unique to each instance of the class.


43. What is the purpose of the "transient" keyword in Java?

The "transient" keyword is used to indicate that a variable should not be serialized during object serialization.


44. What is the difference between method overriding and method overloading?

Method overriding occurs when a subclass provides its own implementation of a method already defined in its superclass, while method overloading occurs when multiple methods in the same class have the same name but different parameters.


45. What is the purpose of the "volatile" keyword in Java?

The "volatile" keyword is used to indicate that a variable's value may be modified by multiple threads, ensuring that the latest value is always read and written.


46. What is the purpose of the "throws" keyword in Java?

The "throws" keyword is used to declare that a method may throw certain exceptions. It is used in the method signature.


47. What are anonymous classes in Java?

Anonymous classes are classes without a name that are defined and instantiated in a single statement. They are useful for implementing interfaces or extending classes on the fly.


48. What is the purpose of the "assert" keyword in Java?

The "assert" keyword is used to perform assertion testing. It allows developers to verify certain conditions during program execution and can be enabled or disabled.


49. What is the difference between a final class and a final method?

A final class cannot be subclassed, while a final method cannot be overridden in a subclass.


50. What is the difference between a HashSet and a TreeSet?

HashSet is an unordered collection that does not allow duplicate elements, while TreeSet is a sorted collection that does not allow duplicate elements.

Comments

Popular posts from this blog

Explore essential Java programs commonly asked in interviews, offering valuable coding insights and practice.

Here is the content refined for clarity and professionalism suitable for someone preparing for a QA Automation interview:

Comprehensive Selenium WebDriver Syntax for Effective Test Automation