Thursday, February 12, 2009

What is the difference between Difference between doGet() and doPost()

Question :What is the difference between Difference between doGet() and doPost()?
Answer :A doGet() method is limited with 2k of data to be sent, and doPost() method doesn’t have this limitation. A request string for doGet() looks like the following:http://www. interviewhelper.org/svt1?p1=v1&p2=v2&…&pN=vNdoPost() method call doesn’t need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it’s impossible to guess the data transmitted to a servlet only looking at a request string

What is the difference between Difference between doGet() and doPost()

Question :What is the difference between Difference between doGet() and doPost()?
Answer :A doGet() method is limited with 2k of data to be sent, and doPost() method doesn’t have this limitation. A request string for doGet() looks like the following:http://www.interviewhelper.org/svt1?p1=v1&p2=v2&…&pN=vNdoPost() method call doesn’t need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it’s impossible to guess the data transmitted to a servlet only looking at a request string

What is preinitialization of a servlet

Question :What is preinitialization of a servlet?
Answer :A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet

Explain ServletContext

Question :Explain ServletContext?
Answer :ServletContext interface is a window for a servlet to view it’s environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container’s version. Every web application has one and only one ServletContext and is accessible to all active resource of that application.

Explain the directory structure of a web application

Question :Explain the directory structure of a web application?
Answer :The directory structure of a web application consists of two parts.A private directory called WEB-INFA public resource directory which contains public resource folder.WEB-INF folder consists of1. web.xml2. classes directory3. lib directory

What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext

Question :What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext?
Answer :The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a “/” it is interpreted as relative to the current context root. The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a “/” and are interpreted as relative to curent context root.

Explain the life cycle methods of a Servlet.

Question :Explain the life cycle methods of a Servlet.?
Answer :The javax.servlet.Servlet interface defines the three methods known as life-cycle method.public void init(ServletConfig config) throws ServletExceptionpublic void service( ServletRequest req, ServletResponse res) throws ServletException, IOExceptionpublic void destroy()First the servlet is constructed, then initialized wih the init() method.Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet. The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized.

Why won’t the JVM terminate when I close all the application windows

Question :Why won’t the JVM terminate when I close all the application windows?
Answer :The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.

Which Swing methods are thread-safe

Question :Which Swing methods are thread-safe?
Answer :The only thread-safe methods are repaint(), revalidate(), and invalidate()

Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater

Question :Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater?
Answer :I want to update a Swing component but I’m not in a callback. If I want the update to happen immediately (perhaps for a progress bar component) then I’d use invokeAndWait. If I don’t care when the update occurs, I’d use invokeLater.

If your UI seems to freeze periodically, what might be a likely reason

Question :If your UI seems to freeze periodically, what might be a likely reason?
Answer :A callback implementation like ActionListener.actionPerformed or MouseListener.mouseClicked is taking a long time to execute thereby blocking the event dispatch thread from processing other UI events.

In what context should the value of Swing components be updated directly

Question :In what context should the value of Swing components be updated directly?
Answer :Swing components should be updated directly only in the context of callback methods invoked from the event dispatch thread. Any other context is not thread safe?

Why should the implementation of any Swing callback (like a listener) execute quickly

Question :Why should the implementation of any Swing callback (like a listener) execute quickly?
Answer :Because callbacks are invoked by the event dispatch thread which will be blocked processing other events for as long as your method takes to execute.

How would you detect a keypress in a JComboBox

Question :How would you detect a keypress in a JComboBox?
Answer :This is a trick. most people would say ‘add a KeyListener to the JComboBox’ - but the right answer is ‘add a KeyListener to the JComboBox’s editor component.’

What class is at the top of the AWT event hierarchy

Question :What class is at the top of the AWT event hierarchy?
Answer :java.awt.AWTEvent. if they say java.awt.Event, they haven’t dealt with swing or AWT in a while.
google_ad_client = "pub-8716701302248821";google_ad_slot = "5004572289";google_ad_width = 468;google_ad_height = 15;
window.google_render_ad();

Explain how to render an HTML page using only Swing

Question :Explain how to render an HTML page using only Swing?
Answer :Use a JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane.

What is the difference between the ‘Font’ and ‘FontMetrics’ class

Question :What is the difference between the ‘Font’ and ‘FontMetrics’ class?
Answer :The Font Class is used to render ‘glyphs’ - the characters you see on the screen. FontMetrics encapsulates information about a specific font on a specific Graphics object. (width of the characters, ascent, descent)

If I wanted to use a SolarisUI for just a JTabbedPane, and the Metal UI for everything else, how would I do that

Question :If I wanted to use a SolarisUI for just a JTabbedPane, and the Metal UI for everything else, how would I do that?
Answer :in the UIDefaults table, override the entry for tabbed pane and put in the SolarisUI delegate. (I don’t know it offhand, but I think it’s "com.sun.ui.motiflookandfeel.MotifTabbedPaneUI" - anything simiar is a good answer.)

How would you create a button with rounded edges

Question :How would you create a button with rounded edges?
Answer :there’s 2 ways. The first thing is to know that a JButton’s edges are drawn by a Border. so you can override the Button’s paintComponent(Graphics) method and draw a circle or rounded rectangle (whatever), and turn off the border. Or you can create a custom border that draws a circle or rounded rectangle around any component and set the button’s border to it.

Why does JComponent have add() and remove() methods but Component does not

Question :Why does JComponent have add() and remove() methods but Component does not?
Answer :: because JComponent is a subclass of Container, and can contain other components and jcomponents.

Can a class be it’s own event handler Explain how to implement this

Question :Can a class be it’s own event handler? Explain how to implement this?
Answer :Sure. an example could be a class that extends Jbutton and implements ActionListener. In the actionPerformed method, put the code to perform when the button is pressed.

What happens to the static fields of a class during serialization

Question :What happens to the static fields of a class during serialization?
Answer :There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are 1. Serialization ignores static fields, because they are not part of ay particular state state. 2. Base class fields are only hendled if the base class itself is serializable. 3. Transient fields.

What one should take care of while serializing the object

Question :What one should take care of while serializing the object?
Answer :One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

When you serialize an object, what happens to the object references included in the object

Question :When you serialize an object, what happens to the object references included in the object?
Answer :The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

What is Externalizable interface

Question :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. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

What is the common usage of serialization

Question :What is the common usage of serialization?
Answer :Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

How can I customize the seralization process? i.e. how can one have a control over the serialization process

Question :How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Answer :Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

How can I customize the seralization process? i.e. how can one have a control over the serialization process

Question :How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Answer :Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

Which methods of Serializable interface should I implement

Question :Which methods of Serializable interface should I implement?
Answer :The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

How do I serialize an object to a file

Question :How do I serialize an object to a file?
Answer :The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.

What is serialization

Question :What is serialization?
Answer :Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

Objects are passed by value or by reference

Question :Objects are passed by value or by reference?
Answer :Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .

Primitive data types are passed by reference or pass by value

Question :Primitive data types are passed by reference or pass by value?
Answer :Primitive data types are passed by value.

What type of parameter passing does Java support

Question :What type of parameter passing does Java support?
Answer :In Java the arguments are always passed by value .

Can a top level class be private or protected

Question :Can a top level class be private or protected?
Answer :No. A top level class can not be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.

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

Question :What is the default value of an object reference declared as an instance variable?
Answer :null unless we define it explicitly.

What is the difference between declaring a variable and defining a variable

Question :What is the difference between declaring a variable and defining a variable?
Answer :In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization. e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*

Question :Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
Answer :No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.

Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile

Question :Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
Answer :Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol symbol : class ABCD location: package io import java.io.ABCD;

What are different types of inner classes

Question :What are different types of inner classes?
Answer :Nested top-level classes, Member classes, Local classes, Anonymous classes Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety. Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class. Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable. Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

What are different types of inner classes

Question :What are different types of inner classes?
Answer :Nested top-level classes, Member classes, Local classes, Anonymous classes

What is Overriding

Question :What is Overriding?
Answer :When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

What are Checked and UnChecked Exception

Question :What are Checked and UnChecked Exception?
Answer :A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method• Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method• Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

Can I import same package/class twice Will the JVM load the package twice at runtime

Question :Can I import same package/class twice? Will the JVM load the package twice at runtime?
Answer :One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.

Do I need to import java.lang package any time Why

Question :Do I need to import java.lang package any time? Why?
Answer :No. It is by default loaded internally by the JVM.

Can I have multiple main methods in the same class

Question :Can I have multiple main methods in the same class?
Answer :No the program fails to compile. The compiler says that the main method is already defined in the class.

Can an application have multiple classes having main method

Question :Can an application have multiple classes having main method?
Answer :Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

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

Question :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.

How can one prove that the array is not null but empty using one line of code

Question :How can one prove that the array is not null but empty using one line of code?
Answer :: Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

If I do not provide any arguments on the command line, then the String array of Main method will be empty or null

Question :If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
Answer :It is empty. But not null.

What is the first argument of the String array in main method

Question :What is the first argument of the String array in main method?
Answer :The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name

What if I do not provide the String array as the argument to the method

Question :What if I do not provide the String array as the argument to the method?
Answer :Program compiles but throws a runtime error "NoSuchMethodError".

What if I write static public void instead of public static void

Question :What if I write static public void instead of public static void?
Answer :Program compiles and runs properly.

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

Question :What if the static modifier is removed from the signature of the main method?
Answer :Program compiles. But at runtime throws an error "NoSuchMethodError".

What if the main method is declared as private

Question :What if the main method is declared as private?
Answer :The program compiles properly but at runtime it will give "Main method not public." message.

What is final

Question :What is final?
Answer :A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

What is static in java

Question :What is static in java?
Answer :Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.

What is an abstract class

Question :What is an abstract class?
Answer :: Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships o

Question :State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers?
Answer :: public : Public class is visible in other packages, field is visible everywhere (class must be public too) private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature. protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature. default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package

What is an Iterator

Question :What is an Iterator?
Answer :Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.

What is the difference between a constructor and a method

Question :What is the difference between a constructor and a method?
Answer :A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

Difference between Swing and Awt

Question :Difference between Swing and Awt?
Answer :AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.

Difference between HashMap and HashTable

Question :Difference between HashMap and HashTable?
Answer :The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.

Difference between Vector and ArrayList

Question :Difference between Vector and ArrayList?
Answer :Vector is synchronized whereas arraylist is not.

What is HashMap and Map

Question :What is HashMap and Map?
Answer :Map is Interface and Hashmap is class that implements that.

What are pass by reference and passby value

Question :What are pass by reference and passby value?
Answer :Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

Explain different way of using thread

Question :Explain different way of using thread?
Answer :The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

Describe synchronization in respect to multithreading

Question :Describe synchronization in respect to multithreading?
Answer :With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

What is the purpose of garbage collection in Java, and when is it used

Question :What is the purpose of garbage collection in Java, and when is it used?
Answer :The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

What is the difference between an if statement and a switch statement

Question :What is the difference between an if statement and a switch statement?
Answer :The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed. 198. What is the difference between an Interface and an Abstract class? A: 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. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

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

Question :What are the two basic ways in which classes that can be run as threads may be defined?
Answer :A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.

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

Question :What are the problems faced by Java programmers who don't use layout managers?
Answer :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.

What are synchronized methods and synchronized statements

Question :What are synchronized methods and synchronized statements?
Answer :Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. 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

Which Component subclass is used for drawing and painting

Question :Which Component subclass is used for drawing and painting?
Answer :Canvas

What methods are used to get and set the text label displayed by a Button object

Question :What methods are used to get and set the text label displayed by a Button object?
Answer :getLabel() and setLabel()

What method must be implemented by all threads

Question :What method must be implemented by all threads?
Answer :All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.

When is an object subject to garbage collection

Question :When is an object subject to garbage collection?
Answer :An object is subject to garbage collection when it becomes unreachable to the program in which it is used.

Can an unreachable object become reachable again

Question :Can an unreachable object become reachable again?
Answer :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.

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

Question :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.

What are the Object and Class classes used for

Question :What are the Object and Class classes used for?
Answer :The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.

What is a Java package and how is it used

Question :What is a Java package and how is it used?
Answer :A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

What modifiers may be used with a top-level class

Question :What modifiers may be used with a top-level class?
Answer :A top-level class may be public, abstract, or final.

What is the purpose of a statement block

Question :What is the purpose of a statement block?
Answer :A statement block is used to organize a sequence of statements as a single statement group.

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

Question :What is the difference between the prefix and postfix forms of the ++ operator?
Answer :The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

Can try statements be nested

Question :Can try statements be nested?
Answer :Try statements may be tested.

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

Question :To what value is a variable of the boolean type automatically initialized?
Answer :The default value of the boolean type is false.

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

Question :What is the difference between a public and a non-public class?
Answer :A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

What is the difference between a Scrollbar and a ScrollPane

Question :What is the difference between a Scrollbar and a ScrollPane?
Answer :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.

What is numeric promotion

Question :What is numeric promotion?
Answer :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.

. 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 statemen

Question :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 statemen?
Answer :The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination.

Can an abstract class be final

Question :Can an abstract class be final?
Answer :An abstract class may not be declared as final.176. 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.

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

Question :What are three ways in which a thread can enter the waiting state?
Answer :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.

Which arithmetic operations can result in the throwing of an ArithmeticException

Question :Which arithmetic operations can result in the throwing of an ArithmeticException?
Answer :Integer / and % can result in the throwing of an ArithmeticException.

What is a layout manager

Question :What is a layout manager?
Answer :A layout manager is an object that is used to organize components in a container.

What happens if an exception is not caught

Question :What happens if an exception is not caught?
Answer :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.

How can a dead thread be restarted

Question :How can a dead thread be restarted?
Answer :A dead thread cannot be restarted.

What restrictions are placed on method overriding

Question :What restrictions are placed on method overriding?
Answer :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.

What interface is extended by AWT event listeners

Question :What interface is extended by AWT event listeners?
Answer :All AWT event listeners extend the java.util.EventListener interface.

What is a compilation unit

Question :What is a compilation unit?
Answer :A compilation unit is a Java source code file.

What is the purpose of garbage collection

Question :What is the purpose of garbage collection?
Answer :The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.

How are this and super used

Question :How are this and super used?
Answer :this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.

How are this and super used

Question :How are this and super used?
Answer :this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.

What interface must an object implement before it can be written to a stream as an object

Question :What interface must an object implement before it can be written to a stream as an object?
Answer :An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Which package is always imported by default

Question :Which package is always imported by default?
Answer :The java.lang package is always imported by default.

What happens when you add a double value to a String

Question :What happens when you add a double value to a String?
Answer :The result is a String object.162. What is your platform's default character encoding? If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1..

What is the purpose of the enableEvents() method

Question :What is the purpose of the enableEvents() method?
Answer :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.

What is the difference between the File and RandomAccessFile classes

Question :What is the difference between the File and RandomAccessFile classes?
Answer :The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.

What is a void return type

Question :What is a void return type?
Answer :A void return type indicates that a method does not return a value.

Are true and false keywords

Question :Are true and false keywords?
Answer :The values true and false are not keywords.

What are E and PI

Question :What are E and PI?
Answer :E is the base of the natural logarithm and PI is mathematical value pi.

What classes of exceptions may be thrown by a throw statement

Question :What classes of exceptions may be thrown by a throw statement?
Answer :A throw statement may throw any expression that may be assigned to the Throwable type.

What is the Set interface

Question :What is the Set interface?
Answer :The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

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

Question :If an object is garbage collected, can it become reachable again?
Answer :Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

What an I/O filter

Question :What an I/O filter?
Answer :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.

How are the elements of a GridLayout organized

Question :How are the elements of a GridLayout organized?
Answer :The elements of a GridBad layout are of equal size and are laid out using the squares of a grid.

What are the legal operands of the instanceof operator

Question :What are the legal operands of the instanceof operator?
Answer :The left operand is an object reference or null value and the right operand is a class, interface, or array type.

What state is a thread in when it is executing

Question :What state is a thread in when it is executing?
Answer :An executing thread is in the running state.

What Checkbox method allows you to tell if a Checkbox is checked

Question :What Checkbox method allows you to tell if a Checkbox is checked?
Answer :getState()

Why are the methods of the Math class static

Question :Why are the methods of the Math class static?
Answer :So they can be invoked as if they are a mathematical code library.

How is it possible for two String objects with identical values not to be equal under the == operator

Question :How is it possible for two String objects with identical values not to be equal under the == operator?
Answer :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.

What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1

Question :What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?
Answer :required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component's container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried. In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events.

What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution

Question :What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?
Answer :A method's throws clause must declare any checked exceptions that are not caught within the body of the method.

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

Question :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.

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

Question :How are this () and super () used with constructors?
Answer :this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

What is the difference between a field variable and a local variable

Question :WhBoldat is the difference between a field variable and a local variable?
Answer :A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

What class allows you to read objects directly from a stream

Question :What class allows you to read objects directly from a stream?
Answer :The ObjectInputStream class supports the reading of objects from input streams.

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

Question :What class of exceptions are generated by the Java run-time system?
Answer :The Java runtime system generates RuntimeException and Error exceptions.

What is the difference between a Choice and a List

Question :What is the difference between a Choice and a List?
Answer :A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.

Wednesday, February 11, 2009

Name four Container classes

Question :Name four Container classes?
Answer :Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

What is the return type of a program's main() method

Question :What is the return type of a program's main() method?
Answer :A program's main() method has a void return type.

What is casting

Question :What is casting?
Answer :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.

What happens when you invoke a thread's interrupt method while it is sleeping or waiting

Question :What happens when you invoke a thread's interrupt method while it is sleeping or waiting?
Answer :When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.

Which non-Unicode letter characters may be used as the first character of an identifier

Question :Which non-Unicode letter characters may be used as the first character of an identifier?
Answer :The non-Unicode letter characters $ and _ may appear as the first character of an identifier

What restrictions are placed on method overloading

Question :What restrictions are placed on method overloading?
Answer :Two methods may not have the same name and argument list but different return types.

How can the Checkbox class be used to create a radio button

Question :How can the Checkbox class be used to create a radio button?
Answer :By associating Checkbox objects with a CheckboxGroup.

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

Question :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.

Which class is the immediate superclass of the Container class

Question :Which class is the immediate superclass of the Container class?
Answer :Component

When is the finally clause of a try-catch-finally statement executed

Question :When is the finally clause of a try-catch-finally statement executed?
Answer :The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.

When does the compiler supply a default constructor for a class

Question :When does the compiler supply a default constructor for a class?
Answer :The compiler supplies a default constructor for a class if no other constructors are provided.

How does multithreading take place on a computer with a single CPU

Question :How does multithreading take place on a computer with a single CPU?
Answer :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.

Which Math method is used to calculate the absolute value of a number

Question :Which Math method is used to calculate the absolute value of a number?
Answer :The abs() method is used to calculate absolute values.

What is the purpose of the File class

Question :What is the purpose of the File class?
Answer :The File class is used to create objects that provide access to the files and directories of a local file system.

Can an exception be rethrown

Question :Can an exception be rethrown?
Answer :Yes, an exception can be rethrown.

What is the difference between the paint() and repaint() methods

Question :What is the difference between the paint() and repaint() methods?
Answer :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.

What is the difference between static and non-static variables

Question :What is the difference between static and non-static variables?
Answer :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.

What modifiers can be used with a local inner class

Question :What modifiers can be used with a local inner class?
Answer :A local inner class may be final or abstract.

What is the Collection interface

Question :What is the Collection interface?
Answer :The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.

What advantage do Java's layout managers provide over traditional windowing systems

Question :What advantage do Java's layout managers provide over traditional windowing systems?
Answer :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.

How are the elements of a GridBagLayout organized

Question :How are the elements of a GridBagLayout organized?
Answer :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.

What is the difference between a while statement and a do statement

Question :What is the difference between a while statement and a do statement?
Answer :A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

How can a GUI component handle its own events

Question :How can a GUI component handle its own events?
Answer :A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

What event results from the clicking of a button

Question :What event results from the clicking of a button?
Answer :The ActionEvent event is generated as the result of the clicking of a button.

Is a class a subclass of itself

Question :Is a class a subclass of itself?
Answer :A class is a subclass of itself.

What is the highest-level event class of the event-delegation model

Question :What is the highest-level event class of the event-delegation model?
Answer :The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.

What modifiers may be used with an interface declaration

Question :What modifiers may be used with an interface declaration?
Answer :An interface may be declared as public or abstract.

What restrictions are placed on the values of each case of a switch statement

Question :What restrictions are placed on the values of each case of a switch statement?
Answer :During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

What is the relationship between an event-listener interface and an event-adapter class

Question :What is the relationship between an event-listener interface and an event-adapter class?
Answer :An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

Is "abc" a primitive value

Question :Is "abc" a primitive value?
Answer :The String literal "abc" is not a primitive value. It is a String object.

What is the relationship between clipping and repainting

Question :What is the relationship between clipping and repainting?
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.

Which class should you use to obtain design information about an object

Question :Which class should you use to obtain design information about an object?
Answer :The Class class is used to obtain information about an object's design.

Name the eight primitive Java types

Question :Name the eight primitive Java types?
Answer :The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Is &&= a valid Java operator

Question :Is &&= a valid Java operator?
Answer :No, it is not.

. How are the elements of a CardLayout organized

Question :How are the elements of a CardLayout organized?
Answer :The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.

Which TextComponent method is used to set a TextComponent to the read-only state

Question :Which TextComponent method is used to set a TextComponent to the read-only state?
Answer :setEditable()

What is the purpose of the System class

Question :What is the purpose of the System class?
Answer :The purpose of the System class is to provide access to system resources.

For which statements does it make sense to use a label

Question :For which statements does it make sense to use a label?
Answer :The only statements for which it makes sense to use a label are those statements that can enclose a break or continue statement.

inherit the constructors of its superclass

Question :inherit the constructors of its superclass?
Answer :A class does not inherit constructors from any of its super classes.

What is the Map interface

Question :What is the Map interface?
Answer :The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.99. Does a class

What is the SimpleTimeZone class

Question :What is the SimpleTimeZone class?
Answer :The SimpleTimeZone class provides support for a Gregorian calendar.
google_ad_client = "pub-8716701302248821";google_ad_slot = "5004572289";google_ad_width = 468;google_ad_height = 15;
window.google_render_ad();

. If a class is declared without any access modifiers, where may the class be accessed

Question :If a class is declared without any access modifiers, where may the class be accessed?
Answer :A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

What classes of exceptions may be caught by a catch clause

Question :What classes of exceptions may be caught by a catch clause?
Answer :A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy

Question :What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Answer :The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

What happens when a thread cannot acquire a lock on an object

Question :What happens when a thread cannot acquire a lock on an object?
Answer :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.

How is rounding performed under integer division

Question :How is rounding performed under integer division?
Answer :The fractional part of the result is truncated. This is known as rounding toward zero.

What is the difference between the Font and FontMetrics classes

Question :What is the difference between the Font and FontMetrics classes?
Answer :The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

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

Question :Is the ternary operator written x : y ? z or x ? y : z?
Answer :It is written x ? y : z.

Can an object be garbage collected while it is still reachable

Question :Can an object be garbage collected while it is still reachable?
Answer :A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected..

Which class is extended by all other classes

Question :Which class is extended by all other classes?
Answer :The Object class is extended by all other classes.

What is the difference between a Window and a Frame

Question :What is the difference between a Window and a Frame?
Answer :The Frame class extends Window to define a main application window that can have a menu bar.

What is the % operator

Question :What is the % operator?
Answer :It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.

When can an object reference be cast to an interface reference

Question :When can an object reference be cast to an interface reference?
Answer :An object reference be cast to an interface reference when the object implements the referenced interface.