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.

1.

What will be the default values of all the elements of an array defined as an instance variable?

Answer»

If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type.

2.

How does a try statement determine which catch clause should be used to handle an exception?

Answer»

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

3.

Can a double value be cast to a byte?

Answer»

Yes, a double value can be cast to a byte.

4.

What is constructor chaining and how is it achieved in Java?

Answer»

A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.

5.

What is the difference between inner class and nested class?

Answer»

When a class is defined within a scope of another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

6.

If a method is declared as protected, where may the method be accessed?

Answer»

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

7.

What are order of precedence and associativity and how are they used?

Answer»

Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

8.

What is an object's lock and which object's have locks?

Answer»

An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock.

9.

Which object oriented Concept is achieved by using overloading and overriding?

Answer»

Polymorphism

10.

Can an Interface extend another Interface?

Answer»

Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

11.

What are the restriction imposed on a static method or a static block of code?

Answer»

A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

12.

Can a class declared as private be accessed outside it's package?

Answer»

No, it's not possible to accessed outside it's package.

13.

What is difference between Path and Classpath?

Answer»

Path and Classpath are operating system level environment variales. Path is defines where the system can find the executables(.exe) files and classpath is used to specify the location of .class files.

14.

What is an enumeration?

Answer»

An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.

15.

Can a vector contain heterogenous objects?

Answer»

Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.

16.

What is the difference between the size and capacity of a Vector?

Answer»

The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.

17.

What is the SimpleTimeZone class?

Answer»

The SimpleTimeZone class provides support for a Gregorian calendar .

18.

What is the GregorianCalendar class?

Answer»

The GregorianCalendar provides support for traditional Western calendars

19.

Which method must be implemented by all threads?

Answer»

All tasks must implement the run() method

20.

Which method is used to create the daemon thread?

Answer»

setDaemon method is used to create a daemon thread.

21.

What is daemon thread?

Answer»

Daemon thread is a low priority thread, which runs intermittently in the back ground doing the garbage collection operation for the java runtime system.

22.

If System.exit (0); is written at the end of the try block, will the finally block still execute?

Answer»

No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.

23.

What is Externalizable interface?

Answer»

Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.

24.

What is Nested top-level class?

Answer»

If a class is declared within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Nested top-level class is an Inner class.

25.

Is there any need to import java.lang package?

Answer»

No, there is no need to import this package. It is by default loaded internally by the JVM.

26.

What environment variables do I need to set on my machine in order to be able to run Java programs?

Answer»

CLASSPATH and PATH are the two variables.

27.

Why Generics are used in Java?

Answer»

Generics provide compile-time type safety that allows programmers to catch invalid types at compile time. Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types.

28.

Which class represents the socket that both the client and server use to communicate with each other?

Answer»

java.net.Socket class represents the socket that both the client and server use to communicate with each other.

29.

Which class is used by server applications to obtain a port and listen for client requests?

Answer»

java.net.ServerSocket class is used by server applications to obtain a port and listen for client requests

30.

Disadvantages of Java Sockets?

Answer»

Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.

31.

Advantages of Java Sockets?

Answer»

Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications. It cause low network traffic.

32.

What is a Socket?

Answer»

Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.

33.

Define Network Programming?

Answer»

It refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network.

34.

Define canvas?

Answer»

It is a simple drawing surface which are used for painting images or to perform other graphical operations.

35.

Define code as an attribute of Applet?

Answer»

It is used to specify the name of the applet class.

36.

Which method is called by Applet class to load an image?

Answer»

getImage(URL object, filename) is used for this purpose.

37.

Why is the role of init() method under applets?

Answer»

It initializes the applet and is the first method to be called.

38.

Life cycle of an applet includes which steps?

Answer»

Life cycle involves the following steps −

  • Initialization

  • Starting

  • Stopping

  • Destroying

  • Painting

39.

Explain main thread under Thread class execution?

Answer»

The main thread is created automatically and it begins to execute immediately when a program starts. It ia thread from which all other child threads originate.

40.

What is currentThread()?

Answer»

It is a public static method used to obtain a reference to the current thread.

41.

Explain isAlive() method under Thread class?

Answer»

It is used to find out whether a thread is still running or not.

42.

Explain suspend() method under Thread class>

Answer»

It is used to pause or temporarily stop the execution of the thread.

43.

Where import statement is used in a Java program?

Answer»

Import statement is allowed at the beginning of the program file after package statement.

44.

Break statement can be used as labels in Java?

Answer»

Yes, an example can be break one;

45.

Which number is denoted by leading 0x or 0X in java?

Answer»

Hexadecimal Numbers are denoted by leading 0x or 0X in java, example − 0XF

46.

Which number is denoted by leading zero in java?

Answer»

Octal Numbers are denoted by leading zero in java, example: 06

47.

Does Java allow Default Arguments?

Answer»

No, Java does not allow Default Arguments.

48.

What is the immediate superclass of Menu?

Answer»

MenuItem class

49.

What is the range of the short type?

Answer»

The range of the short type is -(2^15) to 2^15 - 1.

50.

Which method of the Component class is used to set the position and size of a component?

Answer»

setBounds() method is used for this purpose.