Basic Interview Questions in Java for Freshers with Answer
Here are some basic interview questions and answers for Java:
Q: What is JavaScript and what is it used for?
Q: What is the difference between let and var in JavaScript?
Q: What is hoisting in JavaScript?
Q: What is the event loop in JavaScript?
Q: What is a closure in JavaScript?
Q: What is a callback function in JavaScript?
Q: What is the difference between an object and a class in Java?
Ans: An object is an instance of a class, while a class is a blueprint or template for creating objects.
Q: What is the difference between a constructor and a method in Java?
Ans: A constructor is a special type of method that is used to initialize an object when it is created, while a method is a function that performs a specific task and may or may not return a value.
Q: What is the difference between a static method and an instance method in Java?
Ans: A static method belongs to a class and can be called without creating an object, while an instance method belongs to an object and can only be called on a specific instance of a class.
Q: What is the purpose of the main() method in Java?
Ans: The main() method is the entry point of a Java program and is where the program starts executing.
Q: What is the difference between the equals() method and the == operator in Java?
Ans: The equals() method is used to compare the contents of two objects, while the == operator is used to compare the memory addresses of two objects.
Q: What is the purpose of an interface in Java?
Ans: An interface is a collection of abstract methods that a class can implement. It is used to define a contract for the behavior of a class, but does not provide any implementation details.
Q: What is the difference between an Array List and a LinkedList in Java?
Ans: An ArrayList is backed by an array and provides constant-time performance for the basic operations (get and set), while a LinkedList is backed by a linked list and provides constant-time performance for insertion and deletion operations.
Q: What is the difference between synchronous and asynchronous code in JavaScript?
Ans: Synchronous code is executed in the order in which it is called, while asynchronous code is executed at a later time, independent of the main execution thread.
Q: What is the difference between a forEach loop and a for loop in JavaScript?
Ans: A forEach loop is used to iterate over an array and execute a callback function for each element, while a for loop is more general and can be used to iterate over arrays, as well as other types of data
No comments
Note: Only a member of this blog may post a comment.