Advanced Java Interview Questions -6

Advanced Java Interview Questions -6

1. What are the legal operands of the instanceof operator?

The left operand is an object reference or null value and the right operand is a class, interface, or array type.

2. How are the elements of a GridBagLayout organized?

The elements of a GridBagLayout are of equal size and are laid out using the squares of a grid.

3. What an I/O filter?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

4. If an object is garbage collected, can it become reachable again?

Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

5. What is the Set interface?

The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

6. What classes of exceptions may be thrown by a throw statement?

A throw statement may throw any expression that may be assigned to the Throwable type.

7. What are E and PI?

E is the base of the natural logarithm and PI is mathematical value pi.

8. Are true and false keywords?

The values true and false are not keywords.

9. What is a void return type?

A void return type indicates that a method does not return a value.

10. What method is invoked to cause an object to begin executing as a separate thread?

The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.

11. Name two subclasses of the TextComponent class.

TextField and TextArea.

12. Which containers may have a MenuBar?

Frame.

13. How are commas used in the intialization and iteration parts of a for statement?

Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.

14. What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?

The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination.

15. What is numeric promotion?

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

16. What is the purpose of the File class?

The File class is used to create objects that provide access to the files and directories of a local file system.

17. Can an exception be rethrown?

Yes, an exception can be rethrown.
18. Which Math method is used to calculate the absolute value of a number?

The abs() method is used to calculate absolute values.

19. How does multithreading take place on a computer with a single CPU?

The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

20. When does the compiler supply a default constructor for a class?

The compiler supplies a default constructor for a class if no other constructors are provided.

21. What invokes a thread's run() method?

After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.

22. Which class is extended by all other classes?

The Object class is extended by all other classes.

23. Can an object be garbage collected while it is still reachable?

A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected..

24. Is the ternary operator written x : y ? z or x ? y : z ?

It is written x ? y : z.

25. What is the difference between the Font and FontMetrics classes?

The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

26. What is the Map interface?

The Map interface replaces the JDK 1.1

27. What happens if an exception is not caught?

An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

28. What is a layout manager?

A layout manager is an object that is used to organize components in a container.

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

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

30. What are three ways in which a thread can enter the waiting state?

A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

31. What are the problems faced by Java programmers who don't use layout managers?

Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

32. What are the two basic ways in which classes that can be run as threads may be defined?

A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.

33. What is the difference between the prefix and postfix forms of the ++ operator?

The prefix form performs the increment operation and returns the value of the increment operation.

34. Can try statements be nested?

Try statements may be tested.

35. To what value is a variable of the boolean type automatically initialized?

The default value of the boolean type is false.

36. Can an unreachable object become reachable again?

An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.

37. When is an object subject to garbage collection?

An object is subject to garbage collection when it becomes unreachable to the program in which it is used.

38. What is the difference between a Scrollbar and a ScrollPane?

A Scrollbar is a Component, but not a Container. A ScrollPane is a Container.

A ScrollPane handles its own events and performs its own scrolling.

39. What is the difference between a public and a non-public class?

A public class may be accessed outside of its package.

A non-public class may not be accessed outside of its package.

The postfix form returns the current value all of the expression and then performs the increment operation on that value.

40. What is the purpose of a statement block?

A statement block is used to organize a sequence of statements as a single statement group.

41. What is the ResourceBundle class?

The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Dictionary class and is used associate keys with values.

42 How can a GUI component handle its own events in Java Programming?

A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

43 How are the elements of a GridBagLayout organized in Java Programming?

The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

44 What advantage do Java’s layout managers provide over traditional windowing systems?

Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

45 What are the problems faced by Java programmers who don’t use layout managers?

Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

46 What is the purpose of the Runtime class in Java Programming?

The purpose of the Runtime class is to provide access to the Java runtime system in Java Programming.

47 What is the purpose of the System class in Java Programming?

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

48 What is the purpose of the finally clause of a try-catch-finally statement in Java Programming?

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

49 What classes of exceptions may be caught by a catch clause in Java Programming?

A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

50 If a class is declared without any access modifiers, where may the class be accessed in Java Programming?

A class that is declared without any access modifiers is said to have package or friendly access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

51  What is the difference between static and non-static variables in Java Programming?

A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

52  What is the difference between the paint() and repaint() methods in Java Programming?

The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

53 What is the purpose of the File class in Java Programming?

The File class is used to create objects that provide access to the files and directories of a local file system.

54 What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy in Java Programming?

The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

55 What is the difference between a static and a non-static inner class in Java Programming?

A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

56 What is an object’s lock and which object’s have locks in Java Programming?

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. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

57  When can an object reference be cast to an interface reference in Java Programming?

An object reference be cast to an interface reference when the object implements the referenced interface.

58  What is the difference between a Window and a Frame in Java Programming?

The Frame class extends Window to define a main application window that can have a menu bar.

59  What do heavy weight components mean in Java Programming?

Heavy weight components like Abstract Window Toolkit (AWT), 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. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface. For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavyweight.

60 How are this() and super() used with constructors in Java Programming?

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor in Java Programming.

61 What is the difference between the Boolean & operator and the && operator in Java Programming?

If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator
is applied to the operand. When an expression involving the && operator is evaluated, the first operand is
evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is
then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the
second operand is skipped.

Operator & has no chance to skip both sides evaluation and && operator does. If asked why, give details as above.

62 Which class should you use to obtain design information about an object in Java Programming?

The Class class is used to obtain information about an object’s design.


63 How does multithreading take place on a computer with a single CPU in Java Programming?

The operating system’s task scheduler allocates execution time to multiple tasks. By quickly switching between
executing tasks, it creates the impression that tasks execute sequentially.

64 What restrictions are placed on method overloading in Java Programming?

Two methods may not have the same name and argument list but different return types.

65 What is the Map interface in Java Programming?

The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.

66 Does a class inherit the constructors of its superclass in Java Programming?

A class does not inherit constructors from any of its superclasses.

67 Name primitive Java types?

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

68 What is the Gregorian Calendar class in Java Programming?

The Gregorian Calendar provides support for traditional Western calendars in Java Programming.

69 What is the SimpleTimeZone class in Java Programming?

The SimpleTimeZone class provides support for a Gregorian calendar in Java Programming.


70 Which package has light weight components in Java Programming?

javax. Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components in Java Programming.

71 What are peerless components in Java Programming?

The peerless components are called light weight components.

72 What is the difference between the Font and FontMetrics classes in Java Programming?

The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

73 What happens when a thread cannot acquire a lock on an object in Java Programming?

If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object’s lock, it enters the waiting state until the lock becomes available.

74 What restrictions are placed on method overriding in Java Programming?

Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

75 What is casting in Java Programming?

There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

76 Name Container classes in Java Programming?

Container classes in Java:

Window,
Frame,
Dialog,
FileDialog,
Panel,
Applet,
or ScrollPane

77 What class allows you to read objects directly from a stream in Java Programming?

The ObjectInputStream class supports the reading of objects from input streams.

78  Which Container method is used to cause a container to be laid out and redisplayed in Java Programming?

validate();
Container method is used to cause a container to be laid out and redisplayed in Java Programming

79 What is the Properties class in Java Programming?

The properties class is a subclass of Hash table that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

80 Which class is the super class for every class in Java Programming?

Object class is the super class for every class in Java Programming

81 What invokes a thread’s run() method in Java Programming?

After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread’s run() method when the thread is initially executed.

82 Define class and object. Explain them with an example using java.

Class: A class is a program construct which encapsulates data and operations on data. In object oriented programming, the class can be viewed as a blue print of an object

83 Explain class vs. instance with example using java.

A class is a program construct which encapsulates data and operations on data. It is a blue print of an object

84 What is a method? Provide several signatures of the methods.

A java method is a set of statements to perform a task. A method is placed in a class. Signatures of methods: The
name of the method, return type and the number of parameters comprise the method signature

86 Explain the difference between instance variable and a class variable. Provide example to explain them.

An instance variable is a variable which has one copy per object / instance. That means every object will have one copy of it

87 Explain how to create instance of a class by giving an example. 

Java supports 3 ways of creating instances. By using new operator – Ex : Product prodMouse = new Product();

88 Define an abstract class. Explain its purpose.

A class with one of more abstract methods is called an Abstract class. An abstract method is a method with signature without code in it

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

An abstract class can have both abstract and concrete methods whereas an interface can have only method signatures

90 What is singleton class? Where is it used?

A class is defined as singleton class, if and only if it can create only one object. This class is useful when
only one object is to be used in the application. The following are some of the uses of singleton class

91 What is a native method?

A native method is a method which is implemented in a non-java language that is targeted for a single machine
type. Native methods can pass or return Java objects

92 What is the difference between a public and a non-public class?

A class with access specifier ‘public’ can be accessed across the packages. A package is like a folder in GUI
based operating systems. For example, the “public class String” class is a public class which can be accessed
across the packages

93 What is the purpose of the Runtime class?

The java runtime system can be accessed by the Runtime class. The runtime information – memory availability,
invoking the garbage collector is possible by using Runtime class

94 What is the difference between a static and a non-static inner class?

Like static methods and static members are defined in a class, a class can also be static. To specify the static
class, prefix the keyword ‘static’ before the keyword ‘class’

95 What is the difference between the String and StringBuffer classes?

String class is immutable. The characters of string objects can not be changed / modified. StringBuffer is
mutable. The characters of StringBuffer objects can be modified / changed

97 What is the Dictionary class?

The Dictionary class is an abstract class. The class maps keys to values. The classes such as HashTable are the
sub classes of the abstract class Dictionary

98 What is the ResourceBundle class?

A ResourceBundle is a group of related sub classes which are sharing the same base name. For example, ButtonLabel
is the base name. All the characters following the base name indicates the following elements respectively

99 What is the Vector class?

The capability of implementing a growable array of object is provided by the class Vector

100 What is the SimpleTimeZone class?

SimpleTimeZone is a concrete subclass of TimeZone class. The TimeZone class represents a time zone that is to be
used with Gregorian calendar

101 What is the purpose of the System class?

System class is provided with useful fields (static members) that are pertaining to the environment

102 How are this() and super() used with constructors?

this() constructor is invoked within a method of a class, if the execution of the constructor is to be done before
the functionality of that method

103 How is it possible in Java Programming for two String objects with identical values not to be equal under the
operator?

The  operator compares two objects to determine if they are the same object in memory. It is possible for two
String objects to have the same value, but located indifferent areas of memory.

104 What an I/O filter in Java Programming?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way
as it is passed from one stream to another.

105 What is the Set interface in Java Programming?

The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow
duplicate elements.

106 What is the purpose of the enableEvents() method in Java Programming?

The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a
listener is added to an object for a particular event. The enableEvents() method is used by objects that handle
events by overriding their event-dispatch methods.

107 Is Java a super set of JavaScript?

No. They are completely different. Some syntax may be similar.

------------------------------------
Also Read:
Advanced Java Interview Questions -1

Advanced Java Interview Questions -2

Advanced Java Interview Questions -3

Advanced Java Interview Questions -4

Advanced Java Interview Questions -5

Advanced Java Interview Questions -6

Advanced Java Interview Questions -7

Advanced Java Interview Questions -8

Advanced Java Interview Questions -9

Advanced Java Interview Questions -10

Advanced Java Interview Questions -11

Advanced Java Interview Questions -12

Advanced Java Interview Questions -13

Advanced Java Interview Questions -14        

0 comments:

Post a Comment