Java Interview Questions

JDBC Interview Questions

  1. What are the steps involved in establishing a JDBC connection? This action involves two steps: loading the JDBC driver and making the connection.
  2. How can you load the drivers?
    Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:

    Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);

    Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:

    Class.forName(”jdbc.DriverXYZ”);

JDBC Interview Questions II

  1. How can you use PreparedStatement? This special type of statement is derived from class Statement.If you need a
    Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first.

    PreparedStatement updateSales =
      con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");

Java Applet Interview Questions

  1. What is an Applet? Should applets have constructors?
    - Applets are small programs transferred through Internet, automatically installed and run as part of web-browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java-capable browser. We don’t have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.
  2. What are the Applet’s Life Cycle methods? Explain them? - Following are methods in the life cycle of an Applet:
    • init() method - called when an applet is first loaded. This method is called only once in the entire cycle of an applet. This method usually intialize the variables to be used in the applet.

Java Applet Interview Questions II

  1. Can applets on different pages communicate with each other?
    - No, Not Directly. The applets will exchange the information at one meeting place either on the local file system or at remote system.
  2. How do I determine the width and height of my application?
    - Use the getSize() method, which the Applet class inherits from the Component class in the Java.awt package. The getSize() method returns the size of the applet as a Dimension object, from which you extract separate width, height fields. The following code snippet explains this:

    Dimension dim = getSize();
    int appletwidth = dim.width();
    int appletheight = dim.height();

Java AWT Interview Questions

  1. What is meant by Controls and what are different types of controls? - Controls are componenets that allow a user to interact with your application. The AWT supports the following types of controls:
    • Labels
    • Push buttons
    • Check boxes
    • Choice lists
    • Lists
    • Scroll bars
    • Text components

    These controls are subclasses of Component.

  2. Which method of the component class is used to set the position and the size of a component? - setBounds(). The following code snippet explains this:
    txtName.setBounds(x,y,width,height);

    places upper left corner of the text field txtName at point (x,y) with the width and height of the text field set as width and height.

Pages (21): « First ... « 2 3 4 [5] 6 7 8 » ... Last »