Core Java Interview Questions and Answers Part 4


Q: What is an Interface?

A: An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

Q: Give some features of Interface?

A: It includes:

  • An interface cannot be instantiated.
  • An interface does not contain any constructors.
  • All of the methods in an interface are abstract.

Q: Define Packages in Java?

A: A Package can be defined as a grouping of related types(classes, interfaces, enumerations, and annotations ) providing access protection and namespace management.

Q: Why Packages are used?

A: Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations, and annotations, etc., easier.

Q: What do you mean by Multi-threaded program?

A: A multi-threaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.

Q: What are the two ways in which Thread can be created?

A: Thread can be created by implementing the Runnable interface, extending the Thread class.

Q: What is an applet?

A: An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal.

Q: An applet extend which class?

A: An applet extends java.applet.Applet class.

Q: Explain garbage collection in Java?

A: It uses garbage collection to free the memory. By cleaning those objects that are no longer referenced by any of the program.

Q: Define immutable object?

A: An immutable object can’t be changed once it is created.

Q: Explain the usage of this() with constructors?

A: It is used with variables or methods and used to call a constructor of the same class.

Q: Explain Set Interface?

A: It is a collection of an element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.

Q: Explain TreeSet?

A: It is a Set implemented when we want elements in a sorted order.

Q: What is the Comparable Interface?

A: It is used to sort collections and arrays of objects using the Collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered.

Q: Difference between throw and throws?

A: It includes:

  • The throw is used to trigger an exception where as throws is used in the declaration of exception.
  • Without throws, a Checked exception cannot be handled whereas a checked exception can be propagated with throws.

Q: Explain the following line used under Java Program:

public static void main (String args[ ])

A: The following shows the explanation individually:

  • public: it is the access specifier.
  • static: it allows main() to be called without instantiating a particular instance of a class.
  • void: it affirms the compiler that no value is returned by main().
  • main(): this method is called at the beginning of a Java program.
  • String args[]: args parameter is an instance array of class String

Q: Define JRE i.e. Java Runtime Environment?

A: Java Runtime Environment is an implementation of the Java Virtual Machine which executes Java programs. It provides the minimum requirements for executing a Java application.

Q: What is JAR file?

A: JAR files is Java Archive fles and it aggregates many files into one. It holds Java classes in a library. JAR files are built on ZIP file format and have .jar file extension.

 

Q: What is a WAR file?

A: This is Web Archive File and used to store XML, java classes, and JavaServer Pages. which is used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, static Web pages etc.

Q: Define JIT compiler?

A: It improves the runtime performance of computer programs based on bytecode.

Q: What is the difference between object-oriented programming language and object-based programming language?

A: Object-based programming languages follow all the features of OOPs except Inheritance. JavaScript is an example of object-based programming languages.

Q: What is the purpose of default constructor?

A: The Java compiler creates a default constructor only if there is no constructor in the class.

Q: Can a constructor be made final?

A: No, this is not possible.


Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.