Skip to main content

Posts

Showing posts from October, 2007

Java Swings

What is the difference between Swing and AWT components? AWT components are heavy-weight, whereas Swing components are lightweight. Hence Swing works faster than AWT. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component. Pluggable look and feel possible using java Swing. Also, we can switch from one look and feel to another at runtime in swing which is not possible in AWT. Name the containers which use Border Layout as their default layout? window, Frame and Dialog classes. Name Container classes. Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane How can a GUI component handle its own events? A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener. What is the difference between the paint() and repaint() methods? The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invo...

Core Java Interview Qns

What if the main method is declared as private? The program compiles properly but at runtime it will give "Main method not public." message. What is meant by pass by reference and pass by value in Java? Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value. If you’re overriding the method equals() of an object, which other method you might also consider? hashCode() What is Byte Code? Or What gives java it’s “write once and run anywhere” nature? All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent. Expain the reason for each keyword of public static void main(String args[])? public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public. static: Java environment should be a...

Networking (java.net)

This example demonstrates the declaration and use of all three return types. 1. Define the remote interface. import java.rmi.*; public interface RObject extends Remote { // This return value is primitive. int primitiveRet() throws RemoteException; // This return value implements Serializable. Integer byValueRet() throws RemoteException; // This return value implements Remote. ArgObject byRefRet() throws RemoteException; } public interface ArgObject extends Remote { int aMethod() throws RemoteException; } 2. Define the remote object implementation. import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class RObjectImpl extends UnicastRemoteObject implements RObject { public RObjectImpl() throws RemoteException { super(); } public int primitiveRet() throws RemoteException { return 3000; } public Integer byValueRet() throws RemoteException { return new Integer(2000); } public ArgObject byRefRet() throws RemoteException { return new ArgObjectImpl(); } } 3. Compile the remot...

JDBC Concepts

Connecting to a Database This example uses the JDBC-ODBC bridge to connect to a database called "mydatabase". try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:mydatabase"; Connection con = DriverManager.getConnection( url, "login", "password"); } catch (ClassNotFoundException e) { } catch (SQLException e) { } Creating a Table This example creates a table called "mytable" with three columns: COL_A which holds strings, COL_B which holds integers, and COL_C which holds floating point numbers. try { Statement stmt = con.createStatement(); stmt.executeUpdate("CREATE TABLE mytable ( COL_A VARCHAR(100), COL_B INTEGER, COL_C FLOAT)"); } catch (SQLException e) { } Entering a New Row into a Table This example enters a row containing a string, an integer, and a floating point number into the table called "mytable". try { Statement stmt = connection.createStatement(); stmt.executeUpdate(...

EJB FAQs

What are the design goals of the Enterprise JavaBeansTM architecture? The Enterprise JavaBeans specification defines a standard architecture for implementing the business logic of multi-tier applications as reusable components. In addition to Enterprise JavaBeans components, the architecture defines three other entities:servers,containers, and clients. This architecture incorporates several design goals: Enterprise JavaBeans servers are designed to wrap around legacy systems to provide fundamental services for "containers and the components they contain" Enterprise JavaBeans containers are designed to handle details of "component" life-cycle, transaction, and security management Component developers are free to focus on business logic, since containers provide services automatically by interceding in component method calls. A simple set of callback interfaces are all that a developer needs to implement to participate in container provided services. A client’s view o...

RMI Interview Questions

What is RMI and steps involved in developing an RMI object? Ans: Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine.The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application