Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

What is the difference between the >> and >>> operators?

Answer»

The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.

52.

Describe life cycle of thread?

Answer»

A thread is a execution in a program. The life cycle of a thread include −

  • Newborn state
  • Runnable state
  • Running state
  • Blocked state
  • Dead state
53.

What is type casting?

Answer»

Type casting means treating a variable of one type as though it is another type.

54.

Where and how can you use a private constructor?

Answer»

Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.T

55.

What is dot operator?

Answer»

The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.

56.

What is a Values Collection View ?

Answer»

It is a collection returned by the values() method of the Map Interface, It contains all the objects present as values in the map.

57.

How do you decide when to use ArrayList and LinkedList?

Answer»

If you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList should be used. If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList should be used.

58.

Why deletion in LinkedList is fast than ArrayList?

Answer»

Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.

59.

What are the advantages of ArrayList over arrays?

Answer»

ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.

60.

Can constructor be inherited?

Answer»

No, constructor cannot be inherited.

61.

What is Dynamic Binding(late binding)?

Answer»

Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

62.

What is runtime polymorphism or dynamic method dispatch?

Answer»

Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.

63.

What are synchronized methods and synchronized statements?

Answer»

Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

64.

What is the Locale class?

Answer»

The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

65.

When a thread is created and started, what is its initial state?

Answer»

A thread is in the ready state as initial state after it has been created and started.

66.

Is it necessary that each try block must be followed by a catch block?

Answer»

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block.

67.

What is the difference between error and an exception?

Answer»

An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.

68.

Why do we need wrapper classes?

Answer»

We can pass them around as method parameters where a method expects an object. It also provides utility methods.

69.

What is the default value of an object reference declared as an instance variable?

Answer»

Null, unless it is defined explicitly.

70.

What will happen if static modifier is removed from the signature of the main method?

Answer»

Program throws "NoSuchMethodError" error at runtime.

71.

What is the difference between an Interface and an Abstract class?

Answer»

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.

72.

What are ClassLoaders?

Answer»

A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class.

73.

Can try statements be nested?

Answer»

Yes

74.

Variable of the boolean type is automatically initialized as?

Answer»

The default value of the boolean type is false.

75.

Which arithmetic operations can result in the throwing of an ArithmeticException?

Answer»

Integer / and % can result in the throwing of an ArithmeticException.

76.

How can a dead thread be restarted?

Answer»

A dead thread cannot be restarted.

77.

Under what conditions is an object's finalize() method invoked by the garbage collector?

Answer»

The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.

78.

What class of exceptions are generated by the Java run-time system?

Answer»

The Java runtime system generates RuntimeException and Error exceptions.

79.

Which class is the immediate superclass of the Container class?

Answer»

Component class is the immediate super class.

80.

What is the relationship between clipping and repainting under AWT?

Answer»

When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.

81.

List primitive Java types?

Answer»

The eight primitive types are byte, char, short, int, long, float, double, and boolean.

82.

What is the purpose of the System class?

Answer»

The purpose of the System class is to provide access to system resources.

83.

If a variable is declared as private, where may the variable be accessed?

Answer»

A private variable may only be accessed within the class in which it is declared.

84.

Which Java operator is right associative?

Answer»

The = operator is right associative.

85.

The immediate superclass of the Applet class?

Answer»

Panel is the immediate superclass. A panel provides space in which an application can attach any other component, including other panels.

86.

Does garbage collection guarantee that a program will not run out of memory?

Answer»

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

87.

What is the Collections API?

Answer»

The Collections API is a set of classes and interfaces that support operations on collections of objects.

88.

What is synchronization?

Answer»

Synchronization is the capability to control the access of multiple threads to shared resources. synchronized keyword in java provides locking which ensures mutual exclusive access of shared resource and prevent data race.

89.

What is a transient variable?

Answer»

A transient variable is a variable that may not be serialized during Serialization and which is initialized by its default value during de-serialization,

90.

When ArithmeticException is thrown?

Answer»

The ArithmeticException is thrown when integer is divided by zero or taking the remainder of a number by zero. It is never thrown in floating-point operations.

91.

What's the difference between the methods sleep() and wait()?

Answer»

The code sleep(2000); puts thread aside for exactly two seconds. The code wait(2000), causes a wait of up to two second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

92.

Can you call one constructor from another if a class has multiple constructors?

Answer»

Yes, use this() syntax.

93.

When is the ArrayStoreException thrown?

Answer»

When copying elements between different arrays, if the source or destination arguments are not arrays or their types are not compatible, an ArrayStoreException will be thrown.

94.

Is there any limitation of using Inheritance?

Answer»

Yes, since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation.

95.

What's the difference between constructors and other methods?

Answer»

Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

96.

What is the difference between Swing and AWT components?

Answer»

AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.

97.

Can you write a Java class that could be used both as an applet as well as an application?

Answer»

Yes, just add a main() method to the applet.

98.

How to add menushortcut to menu item?

Answer»

If there is a button instance called b1, you may add menu short cut by calling b1.setMnemonic('F'), so the user may be able to use Alt+F to click the button.

99.

Explain the use of sublass in a Java program?

Answer»

Sub class inherits all the public and protected methods and the implementation. It also inherits all the default modifier methods and their implementation.

100.

What are use cases?

Answer»

It is part of the analysis of a program and describes a situation that a program might encounter and what behavior the program should exhibit in that circumstance.