Java interview questions

Java quiz questions

  • 1.

    What is the advantage of PreparedStatement over Statement ?

    Answer:

    PreparedStatements are precompiled and thus, their performance is much better. Also, PreparedStatement objects can be reused with different input values to their queries.

    View
  • 2.

    What is the purpose Class.forName method ?

    Answer:

    This method is used to method is used to load the driver that will establish a connection to the database.

    View
  • 3.

    Explain the role of Driver in JDBC.

    Answer:

    The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each driver must provide implementations for the following classes of the java.sql package:ConnectionStatementPreparedStatementCallableStatementResultSet and Driver.

    View
  • 4.

    What is JDBC ?

    Answer:

    JDBC is an abstraction layer that allows users to choose between databases. JDBC enables developers to write database applications in Java, without having to concern themselves with the underlying details of a particular database.

    View
  • 5.

    What is the design pattern that Java uses for all Swing components ?

    Answer:

    The design pattern used by Java for all Swing components is the Model View Controller (MVC) pattern.

    View
  • 6.

    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 layout managers aren’t tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.

    View
  • 7.

    How can a GUI component handle its own events ?

    Answer:

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

    View
  • 8.

    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 event. An event adapter provides a default implementation of an event-listener interface.

    View
  • 9.

    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.

    View
  • 10.

    What is the difference between a Window and a Frame ?

    Answer:

    The Frame class extends the Window class and defines a main application window that can have a menu bar.

    View
  • 11.

    How are the elements of a GridBagLayout organized ?

    Answer:

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

    View
  • 12.

    How are the elements of a BorderLayout organized ?

    Answer:

    The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.

    View
  • 13.

    What is the difference between a MenuItem and a CheckboxMenuItem ?

    Answer:

    The CheckboxMenuItem class extends the MenuItem class and supports a menu item that may be either checked or unchecked.

    View
  • 14.

    What is clipping ?

    Answer:

    Clipping is defined as the process of confining paint operations to a limited area or shape.

    View
  • 15.

    Name three Component subclasses that support painting.

    Answer:

    The CanvasFramePanel, and Applet classes support painting.

    View
  • 16.

    Which Swing methods are thread-safe ?

    Answer:

    There are only three thread-safe methods: repaint, revalidate, and invalidate.

    View
  • 17.

    What is the difference between a Scrollbar and a JScrollPane ?

    Answer:

    Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPanehandles its own events and performs its own scrolling.

    View
  • 18.

    What is a layout manager ?

    Answer:

    A layout manager is the used to organize the components in a container.

    View
  • 19.

    What is the difference between a Choice and a List ?

    Answer:

    A Choice is displayed in a compact form that must be pulled down, in order for a user to be able to see the list of all 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.

    View
  • 20.

    What is the applet security manager, and what does it provide ?

    Answer:

    The applet security manager is a mechanism to impose restrictions on Java applets. A browser may only have one security manager. The security manager is established at startup, and it cannot thereafter be replaced, overloaded, overridden, or extended.

    View

© 2017 QuizBucket.org