Learnitweb

Category: Java interview questions

  • What is the benefit of Generics in Collections Framework?

    In Java, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while…

  • What is an exception?

    An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. When an exception occurs within a method, the method creates an exception object and passes this to runtime system. This exception object contains information about the exception, like its type. Creating an exception…

  • Does an interface extends Object?

    Consider the above code. We have defined an interface and have not provided any method in it. Since MyClass implements MyInterface, myInterface reference variable can be used to refer to a MyClass object. Thus, methods provided by interface can be invoked using variable myInterface. We can see from above code that interface has not defined any method, then the question comes to…

  • Why String is immutable in Java?

    This is a design question. Following points can be given to support this: 1. Security – Consider a case when user is provided access to a particular path. But after getting access, user changes the path. This could be a serious security issue. String is the widely used type of parameter for many Java classes.…