-
What is an object's lock and which object's have locks
An object's lock is a mechanism that is used by multiple threads to obtain synchronizedaccess to the object.A thread may execute a synchronized method of an object only after it has acquired theobject's lock. Allobjects and classes have locks. A class's lock is acquired on the class's Class object.
-
What is the difference between the Reader/Writer class hierarchy and theInputStream/OutputStream class hierarchy
The Reader/Writer class hierarchy is character-oriented, and theInputStream/OutputStream class hierarchyis byte-oriented.
-
If a class is declared without any access modifiers, where may the class beaccessed
A class that is declared without any access modifiers is said to have package access. Thismeans that theclass can only be accessed by other classes and interfaces that are defined within thesame package.
-
Is "abc" a primitive value
The String literal "abc" is not a primitive value. It is a String object.
-
What is the relationship between an event-listener interface and an eventadapterclass
An event-listener interface defines the methods that must be implemented by an eventhandler for aparticular kind of event. An event adapter provides a default implementation of an eventlistenerinterface.
-
How can a GUI component handle its own events
A component can handle its own events by implementing the required event-listenerinterface and addingitself as its own event listener.
-
How are the elements of a GridBagLayout organized
The elements of a GridBagLayout are organized according to a grid. However, theelements are of differentsizes and may occupy more than one row or column of the grid. In addition, the rows andcolumns mayhave different sizes.
-
What advantage do Java's layout managers provide over traditional windowingsystems
Java uses layout managers to lay out components in a consistent manner across allwindowing platforms.Since Java's layout managers aren't tied to absolute sizing and positioning, they are ableto accomodateplatform-specific differences among windowing systems.
-
What is the difference between static and non-static variables
A static variable is associated with the class as a whole rather than with specific instancesof a class. Nonstaticvariables take on unique values with each object instance.
-
How does multithreading take place on a computer with a single CPU
The operating system's task scheduler allocates execution time to multiple tasks. Byquickly switchingbetween executing tasks, it creates the impression that tasks execute sequentially.
-
What happens when you invoke a thread's interrupt method while it issleeping or waiting
When a task's interrupt() method is executed, the task enters the ready state. The nexttime the task entersthe running state, an InterruptedException is thrown.
-
What is casting
There are two types of casting, casting between primitive numeric types and castingbetween objectreferences. Casting between numeric types is used to convert larger values, such asdouble values, tosmaller values, such as byte values. Casting between object references is used to refer toan object by acompatible class, interface, or array type reference.
-
What is the difference between the JDK 1.02 event model and the eventdelegationmodelintroduced with JDK 1.1
The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model,components arerequired to handle their own events. If they do not handle a particular event, the event isinherited by (orbubbled up to) the component's container. The container then either handles the event orit is bubbled up toits container and so on, until the highest-level container has been tried.In the event-delegation...
-
How is it possible for two String objects with identical values not to be equalunder the ==operator
The == operator compares two objects to determine if they are the same object inmemory. It is possible fortwo String objects to have the same value, but located indifferent areas of memory.
-
What is the purpose of the enableEvents() method
The enableEvents() method is used to enable an event for a particular object. Normally,an event is enabledwhen a listener is added to an object for a particular event. The enableEvents() method isused by objectsthat handle events by overriding their event-dispatch methods.
-
What is the difference between the File and RandomAccessFile classes
The File class encapsulates the files and directories of the local file system. TheRandomAccessFile classprovides the methods needed to directly access data contained in any part of a file.
-
What is your platform's default character encoding
If you are running Java on English Windows platforms, it is probably Cp1252. If you arerunning Java onEnglish Solaris platforms, it is most likely 8859_1..
-
What restrictions are placed on method overriding
Overridden methods must have the same name, argument list, and return type. Theoverriding method maynot limit the access of the method it overrides. The overriding method may not throwany exceptions thatmay not be thrown by the overridden method.
-
What happens if a try-catch-finally statement does not have a catch clause tohandle anexception that is thrown within the body of the try statement
The exception propagates up to the next higher level try-catch statement (if any) orresults in the program'stermination.
-
What is numeric promotion
Numeric promotion is the conversion of a smaller numeric type to a larger numeric type,so that integer andfloating-point operations may take place. In numerical promotion, byte, char, and shortvalues areconverted to int values. The int values are also converted to long values, if necessary.The long and floatvalues are converted to double values, as required.
Java Interview Questions
Ans