Java Interview Questions

 Q.How can you achieve Multiple Inheritance in Java?

Ans: Java's interface mechanism can be used to implement multiple inheritance, with one important difference from c++ way of doing MI: the inherited interfaces must be abstract. This obviates the need to choose between different implementations, as with interfaces there are no implementations.Q.How ToReplace the Characters in a String? Ans:

  • Replace all occurrences of 'a' with 'o' String newString = string.replace('a', 'o'); Replacing Substrings in a String

static String replace(String str, String pattern, String replace) { int s = 0; int e = 0; StringBuffer result = new StringBuffer(); while ((e = str.indexOf(pattern, s)) >= 0) { result.append(str.substring(s, e)); result.append(replace); s = e+pattern.length(); } result.append(str.substring(s)); return result.toString(); } Converting a String to Upper or Lower Case

  • Convert to upper case

String upper = string.toUpperCase(); // Convert to lower case String lower = string.toLowerCase(); Converting a String to a Number int i = Integer.parseInt("123"); long l = Long.parseLong("123"); float f = Float.parseFloat("123.4"); double d = Double.parseDouble("123.4e10"); Breaking a String into Words String aString = "word1 word2 word3"; StringTokenizer parser = new StringTokenizer(aString); while (parser.hasMoreTokens()) { processWord(parser.nextToken());Q.What is a transient variable? Ans: A transient variable is a variable that may not be serialized. If you don't want some field not to be serialized, you can mark that field transient or static. Q.What is the difference between Serializalble and Externalizable interface? Ans: When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject()two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process. Q.How many methods in the Externalizable interface? Ans: There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal(). Q.How many methods in the Serializable interface? Ans: There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable. Q.How to make a class or a bean serializable? Ans: By implementing either the java.io.Serializable interface, or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchy implements Serializable or Externalizable, that class is serializable. Q.What is the serialization? Ans: The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage. JAVA ONLINE TRAININGQ.What are synchronized methods and synchronized statements?Ans: 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.Q.What is synchronization and why is it important?Ans: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors. Q.What is the purpose of finalization? Ans: The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. Q.What classes of exceptions may be caught by a catch clause? Ans: A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types. Q.What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? Ans: The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented. Q.What happens when a thread cannot acquire a lock on an object? Ans: 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. Q.What restrictions are placed on method overriding? Ans: 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. Q.What restrictions are placed on method overloading? Ans: Two methods may not have the same name and argument list but different return types. Q.How does multithreading take place on a computer with a single CPU? Ans: 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. Q.How is it possible for two String objects with identical values not to be equal under the == operator? Ans: 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. Q.How are this() and super() used with constructors? Ans: this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor. Q.What class allows you to read objects directly from a stream? Ans: The ObjectInputStream class supports the reading of objects from input streams. Q.What is the ResourceBundle class? Ans: 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. Q.What interface must an object implement before it can be written to a stream as an object? Ans: An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object. Q.What is Serialization and deserialization? Ans: Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects. Q.What are the Object and Class classes used for? Ans: 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. Q.Can you write Java code for declaration of multiple inheritance in Java ? Ans: Class C extends A implements B { } Q.What do you mean by multiple inheritance in C++ ? Ans: Multiple inheritance is a feature in C++ by which one class can be of different types. Say class teachingAssistant is inherited from two classes say teacher and Student. Q.Write the Java code to declare any constant (say gravitational constant) and to get its value. Ans: Class ABC { static final float GRAVITATIONAL_CONSTANT = 9.8; public void getConstant() { system.out.println("Gravitational_Constant: " + GRAVITATIONAL_CONSTANT); } }Q.Given two tables Student(SID, Name, Course) and Level(SID, level) write the SQL statement to get the name and SID of the student who are taking course = 3 and at freshman level. Ans: SELECT Student.name, Student.SID FROM Student, Level WHERE Student.SID = Level.SID AND Level.Level = "freshman" AND Student.Course = 3; Q.What do you mean by virtual methods? Ans: virtual methods are used to use the polymorhism feature in C++. Say class A is inherited from class B. If we declare say fuction f() as virtual in class B and override the same function in class A then at runtime appropriate method of the class will be called depending upon the type of the object. Q.What do you mean by static methods? Ans: By using the static method there is no need creating an object of that class to use that method. We can directly call that method on that class. For example, say class A has static function f(), then we can call f() function as A.f(). There is no need of creating an object of class A. Q.What do mean by polymorphism, inheritance, encapsulation? Ans: Polymorhism: is a feature of OOPl that at run time depending upon the type of object the appropriate method is called. Inheritance: is a feature of OOPL that represents the "is a" relationship between different objects(classes). Say in real life a manager is a employee. So in OOPL manger class is inherited from the employee class. Encapsulation: is a feature of OOPL that is used to hide the information.JAVA ONLINE TRAININGQ.What are the advantages of OOPL?Ans: Object oriented programming languages directly represent the real life objects. The features of OOPL as inhreitance, polymorphism, encapsulation makes it powerful. Q.How many methods do u implement if implement the Serializable Interface? Ans: The Serializable interface is just a "marker" interface, with no methods of its own to implement. Q.Are there any other 'marker' interfaces? Ans: java.rmi.Remote java.util.EventListener Q.What is the difference between instanceof and isInstance? Ans: instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() determines if the specified object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is nonnull and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise. Q.why do you create interfaces, and when MUST you use one? Ans: You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved. Q.What's the difference between the == operator and the equals() method? What test does Object.equals() use, and why? Ans: The == operator would be used, in an object sense, to see if the two objects were actually the same object. This operator looks at the actually memory address to see if it actually the same object. The equals() method is used to compare the values of the object respectively. This is used in a higher level to see if the object values are equal. Of course the the equals() method would be overloaded in a meaningful way for whatever object that you were working with. Q.Discuss the differences between creating a new class, extending a class and implementing an interface; and when each would be appropriate. Ans:

  • Creating a new class is simply creating a class with no extensions and no implementations. The signature is as follows

public class MyClass() {

  • Extending a class is when you want to use the functionality of another class or classes. The extended class inherits all of the functionality of the previous class. An example

of this when you create your own applet class and extend from java.applet.Applet. This gives you all of the functionality of the java.applet.Applet class. The signature would look like this public class MyClass extends MyBaseClass { }

  • Implementing an interface simply forces you to use the methods of the interface implemented. This gives you two advantages. This forces you to follow a standard(forces you to use certain methods) and in doing so gives you a channel for polymorphism. This isn’t the only way you can do polymorphism but this is one of the ways.

public class Fish implements Animal { } Q.Name four methods every Java class will have. Ans: public String toString(); public Object clone(); public boolean equals(); public int hashCode(); Q.What does the "abstract" keyword mean in front of a method? A class? Ans: Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it, it is called abstract method.Abstract method has no body. It has only arguments and return type. Abstract methods act as placeholder methods that are implemented in the subclasses. Abstract classes can't be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract. Q.Does Java have destructors? Ans: No garbage collector does the job working in the background Q.Are constructors inherited? Can a subclass call the parent's class constructor? When? Ans: You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because you probably don't want to overide the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language. QDoes Java have "goto"? Ans: No Q.What does the "final" keyword mean in front of a variable? A method? A class? Ans: FINAL for a variable : value is constant FINAL for a method : cannot be overridden FINAL for a class : cannot be derived Core Java Interview Questions and Answers Q.what is a transient variable? Ans: A transient variable is a variable that may not be serialized.JAVA ONLINE TRAININGQ.which containers use a border Layout as their default layout?Ans: The window, Frame and Dialog classes use a border layout as their default layout. Q.Why do threads block on I/O? Ans: Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed Q. How are Observer and Observable used? Ans: Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. Q.What is synchronization and why is it important? Ans: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors. Q.Can a lock be acquired on a class? Ans: Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object. Q.What's new with the stop(), suspend() and resume() methods in JDK 1.2?  Ans: The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.Q.Is null a keyword?Ans: The null value is not a keyword. Q.What is the preferred size of a component? Ans: The preferred size of a component is the minimum component size that will allow the component to display normally. Q.What method is used to specify a container's layout? Ans: The setLayout() method is used to specify a container's layout.Q.Which containers use a FlowLayout as their default layout?Ans: The Panel and Applet classes use the FlowLayout as their default layout. Q.What state does a thread enter when it terminates its processing? Ans: When a thread terminates its processing, it enters the dead state.Q.What is the Collections API?Ans: The Collections API is a set of classes and interfaces that support operations on collections of objects. Q.Which characters may be used as the second character of an identifier, but not as the first character of an identifier? Ans: The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.Q.What is the List interface?Ans: The List interface provides support for ordered collections of objects. Q.How does Java handle integer overflows and underflows? Ans: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation. Q.What is the Vector class? Ans: The Vector class provides the capability to implement a growable array of objects Q.What modifiers may be used with an inner class that is a member of an outer class? Ans: A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.Q.What is an Iterator interface?Ans: The Iterator interface is used to step through the elements of a Collection. Q.What is the difference between the >> and >>> operators? Ans: The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out. Q.Which method of the Component class is used to set the position and size of a component? Ans: setBounds()Q.How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?  Ans: Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns. Q.What is the difference between yielding and sleeping? Ans: When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state. Q.Which java.util classes and interfaces support event handling? Ans: The EventObject class and the EventListener interface support event processing. Q.Is sizeof a keyword? Ans:The sizeof operator is not a keyword JAVA ONLINE TRAININGQ.What are wrapped classes?Ans: Wrapped classes are classes that allow primitive types to be accessed as objects. Q.Does garbage collection guarantee that a program will not run out of memory? Ans: Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection Q.What restrictions are placed on the location of a package statement within a source code file? Ans: A package statement must appear as the first line in a source code file (excluding blank lines and comments).Q.Can an object's finalize() method be invoked while it is reachable?Ans: An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects. Q.What is the immediate superclass of the Applet class? Ans: PanelQ.What is the difference between preemptive scheduling and time slicing?Ans: Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors. Q.Name three Component subclasses that support painting. Ans: The Canvas, Frame, Panel, and Applet classes support painting.Q.What value does readLine() return when it has reached the end of a file?Ans: The readLine() method returns null when it has reached the end of a file.Q.What is the immediate superclass of the Dialog class?Ans: Window Q.What is clipping? Ans: Clipping is the process of confining paint operations to a limited area or shape. Q.What is a native method? Ans: A native method is a method that is implemented in a language other than Java. Q.Can a for statement loop indefinitely? Ans: Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ; Q.What are order of precedence and associativity, and how are they used? Ans: 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 Q.When a thread blocks on I/O, what state does it enter? Ans: A thread enters the waiting state when it blocks on I/O.Q.To what value is a variable of the String type automatically initialized?Ans: The default value of an String type is null.Q.What is the catch or declare rule for method declarations?Ans: If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause. Q.What is the difference between a MenuItem and a CheckboxMenuItem? Ans: The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked. Q.What is a task's priority and how is it used in scheduling? Ans: A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks. Q.What class is the top of the AWT event hierarchy? Ans: The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy. Q.When a thread is created and started, what is its initial state Ans: A thread is in the ready state after it has been created and started.Q.Can an anonymous class be declared as implementing an interface and extending a class?Ans: An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.Q.What is the range of the short type?Ans: The range of the short type is -(2^15) to 2^15 - 1. Q.What is the range of the char type? Ans: The range of the char type is 0 to 2^16 - 1.Q.In which package are most of the AWT events that support the event-delegation model defined?Ans: Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.Q.What is the immediate superclass of Menu?Ans: MenuItem Q.What is the purpose of finalization Ans: The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. Q.Which class is the immediate superclass of the MenuComponent class. Ans: ObjectQ.What invokes a thread's run() method?Ans: 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. Q.What is the difference between the Boolean & operator and the && operator? Ans: 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.Q.Name three subclasses of the Component class.Ans: Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent Q.What is the GregorianCalendar class? Ans: The GregorianCalendar provides support for traditional Western calendars. Q.Which Container method is used to cause a container to be laid out and redisplayed? Ans: validate()Q.What is the purpose of the Runtime class?Ans: The purpose of the Runtime class is to provide access to the Java runtime system. Q.How many times may an object's finalize() method be invoked by the garbage collector? Ans: An object's finalize() method may only be invoked once by the garbage collector.Q.What is the purpose of the finally clause of a try-catch-finally statement?Ans: The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. Q.What is the argument type of a program's main() method? Ans: A program's main() method takes an argument of the String type.Q.Which Java operator is right associative?Ans: The = operator is right associative.Q.What is the Locale class?Ans: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region. Q.Can a double value be cast to a byte? Ans: Yes, a double value can be cast to a byte.Q.What is the difference between a break statement and a continue statement?Ans: A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement. Q.What must a class do to implement an interface? Ans: It must provide all of the methods in the interface and identify the interface in its implements clause. Q.What method is invoked to cause an object to begin executing as a separate thread? Ans: The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread. Q.Name two subclasses of the TextComponent class. Ans: TextField and TextAreaQ.What is the advantage of the event-delegation model over the earlier event-inheritance model?Ans: The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.Q.Which containers may have a MenuBar?Ans: Frame Q.How are commas used in the initialization and iteration parts of a for statement? Ans: Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.Q.What is the purpose of the wait(), notify(), and notifyAll() methods?Ans: The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.Q.What is an abstract method?Ans: An abstract method is a method whose implementation is deferred to a subclass. Q.How are Java source code files named Ans: A Java source code file takes the name of a public class or interface that is defined within the file. A source code file may contain at most one public class or interface. If a public class or interface is defined within a source code file, then the source code file must take the name of the public class or interface. If no public class or interface is defined within a source code file, then the file must take on a name that is different than its classes and interfaces. Source code files use the .java extension. Q.What is the relationship between the Canvas class and the Graphics class? Ans: A Canvas object provides access to a Graphics object via its paint() method.Q.What are the high-level thread states?Ans: The high-level thread states are ready, running, waiting, and dead.Q.What value does read() return when it has reached the end of a file?Ans: The read() method returns -1 when it has reached the end of a file.Q.Can a Byte object be cast to a double value?Ans: No, an object cannot be cast to a primitive value. Q.What is the difference between a static and a non-static inner class? Ans: 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. Q.What is the difference between the String and StringBuffer classes? Ans: String objects are constants. StringBuffer objects are not.Q.If a variable is declared as private, where may the variable be accessed?Ans: A private variable may only be accessed within the class in which it is declared.Q.What is an object's lock and which object's have locks?Ans: 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. Q.What is the Dictionary class? Ans: The Dictionary class provides the capability to store key-value pairs. Q.How are the elements of a BorderLayout organized? Ans: The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container. Q.What is the % operator? Ans: It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand. Q.When can an object reference be cast to an interface reference? Ans: An object reference be cast to an interface reference when the object implements the referenced interface. Q.What is the difference between a Window and a Frame? Ans: The Frame class extends Window to define a main application window that can have a menu bar. Q.Which class is extended by all other classes? Ans: The Object class is extended by all other classes.Q.Can an object be garbage collected while it is still reachable?Ans: A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.. Q.Is the ternary operator written x : y ? z or x ? y : z ? Ans: It is written x ? y : z.Q.What is the difference between the Font and FontMetrics classes?Ans: The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object. Q.How is rounding performed under integer division? Ans: The fractional part of the result is truncated. This is known as rounding toward zero. Q.What happens when a thread cannot acquire a lock on an object? Ans: 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. Q.What is the difference between the Reader/Writer class hierarchy and the InputStream/ OutputStream class hierarchy? Ans: The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.Q.What classes of exceptions may be caught by a catch clause?Ans: A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types. Q.If a class is declared without any access modifiers, where may the class be accessed? Ans: 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.Q.What is the SimpleTimeZone class?Ans: The SimpleTimeZone class provides support for a Gregorian calendar. Q.What is the Map interface? Ans: The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values. Q.Does a class inherit the constructors of its superclass? Ans: A class does not inherit constructors from any of its superclasses. Q.For which statements does it make sense to use a label? Ans: The only statements for which it makes sense to use a label are those statements that can enclose a break or continue statement. Q.What is the purpose of the System class? Ans: The purpose of the System class is to provide access to system resources. Q.Which TextComponent method is used to set a TextComponent to the read-only state? Ans: setEditable()Q.How are the elements of a CardLayout organized?Ans: The elements of a CardLayout are stacked, one on top of the other, like a deck of cards. Q.Is &&= a valid Java operator? Ans: No, it is not.Q.Name the eight primitive Java types.Ans: The eight primitive types are byte, char, short, int, long, float, double, and boolean. Q.Which class should you use to obtain design information about an object? Ans: The Class class is used to obtain information about an object's design.Q.What is the relationship between clipping and repainting?Ans: When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting. Q.Is "abc" a primitive value? Ans: The String literal "abc" is not a primitive value. It is a String object. Q.What is the relationship between an event-listener interface and an event-adapter class? Ans:  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. Q.What restrictions are placed on the values of each case of a switch statement? Ans: During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value. Q.What modifiers may be used with an interface declaration? Ans: An interface may be declared as public or abstract.Q.Is a class a subclass of itself?Ans: A class is a subclass of itself. Q.What is the highest-level event class of the event-delegation model? Ans: The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy. Q.What event results from the clicking of a button? Ans: The ActionEvent event is generated as the result of the clicking of a button. Q.How can a GUI component handle its own events? Ans: A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener. Q.What is the difference between a while statement and a do statement? Ans: 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. Q.How are the elements of a GridBagLayout organized? Ans: 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. Q.What advantage do Java's layout managers provide over traditional windowing systems? Ans: 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 accomodate platform-specific differences among windowing systems.JAVA ONLINE TRAININGQ.What is the Collection interface?Ans: The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates. Q.What modifiers can be used with a local inner class? Ans: A local inner class may be final or abstract.Q.What is the difference between static and non-static variables?Ans: 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. Q.What is the difference between the paint() and repaint() methods? Ans: 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. Q.What is the purpose of the File class? Ans: The File class is used to create objects that provide access to the files and directories of a local file system.Q.Can an exception be rethrown?Ans: Yes, an exception can be rethrown.Q.Which Math method is used to calculate the absolute value of a number?Ans: The abs() method is used to calculate absolute values.Q.How does multithreading take place on a computer with a single CPU?Ans: 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. Q.When does the compiler supply a default constructor for a class? Ans: The compiler supplies a default constructor for a class if no other constructors are provided. Q.When is the finally clause of a try-catch-finally statement executed? Ans: 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. Q.Which class is the immediate superclass of the Container class? Ans: Component JAVA ONLINE TRAININGQ.If a method is declared as protected, where may the method be accessed?Ans: 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. Q.How can the Checkbox class be used to create a radio button? Ans: By associating Checkbox objects with a CheckboxGroup.

Comments

Popular posts from this blog

Searching Blob Documents with the Azure Search Service

IT Blog

Java Web Transaction Monitoring