CS506- Web Design and Development midterm past papers


Web Design and Development

CS506 Midterm Solved Past Papers(Subjective)

Q. How a window handle its own events.

Answer:-  Using listeners is the preferred way of handling events since it is easier than enabling events directly for an object, and the code is clearer. Nonetheless, we should take a look at how you deal with events after calling enableEvents().

Q. Automatic reading in serialization?

Answer:-  System knows how to read data from stream and re-create object in memory. The recreated object is type of “Object” therefore Down-casting is required to convert it into actual type.

Q. Why is executeUpdate() used.

Answer:- Used to execute for INSERT, UPDATE, or DELETE SQL statements. This method returns the number of rows that were affected in the database.

Q. Why we use serialization.

Answer:- Used to send an object to a stream

Q. Differentiate between array and ArrayList .

Answer:- It’s like a resizable array. ArrayList actually comes as a replacement the old “Vector” collection. As we add or remove elements into or from it, it grows or shrinks over time.

Q. Write the syntax to load the oracle driver.

Answer:- Class.forName(“oracle.jdbc.driver.OracleDriver”);

Q. How we process the results of sql query. 5 marks

Answer:-  Process Results of the Query
 The ResultSet provides various getXXX methods that takes a column index or name and returns the data
 The ResultSet maintains the data in the form tables (rows & columns)
 First row has index 1, not 0.
 The next method of ResultSet returns true or false depending upon whether the next row is available (exist) or not and moves the cursor
 Always remember to call next() method at-least once
 To retrieve the data of the column of the current row you need to use the various getters provided by the ResultSet.
 For example, the following code snippet will iterate over the whole ResultSet and illustrates the usage of getters methods
while ( rs.next() ){ //by using column name String name = rs.getString(“columnName”); // or by using column index String name = rs.getString(1);}

Q. GUI drivers?

Answer:-  Java GUI Drivers
 Several well-developed open-source tools
 Some are more for unit testing GUIcomponents. Others are for system oracceptance testing.
 Use various methods for triggering controls:
 Use Robot to generate native OS events
 Generate AWT events
 Drive control components directly

Q. What is advantage of collection over array?

Answer:-Advantage of a collection over an array is that you don’t need to know the eventual size of the collection in order to add objects to it.

Q. What does it mean that a method or class is abstract? 

Answer:-  Abstract classes are used to define only part of an implementation. Because, information is not complete therefore an abstract class cannot be instantiate. However, like regular classes, they can also contain instance variables and methods that are full implemented. The class that inherits from abstract class is responsible to provide details.

Any class with an abstract method (a method has no implementation similar to pure virtual function in C++) must be declared abstract, yet you can declare a class abstract that has no abstract method. If subclass overrides all abstract methods of the super class, than it becomes a concrete (a class whose object can be instantiate) class otherwise we have to declare it as abstract or we can not compile it. The most important aspect of abstract class is that reference of an abstract class can point to the object of concrete classes.

Q. Which method of ResultSetMetaData objective is used to return the suggested value to column label for printout?

Answer:- The getColumnLabel() method returns the suggested column label for printouts.

Q. If a method is declared in protected where it can be accessible?

Answer:- It can be accessible to only to the class to which they belong, and any subclasses.

Q. Write any two steps of painting strategy.

Answer:-  Subclass JPanel

Override the paintComponent(Graphics g) method

Q.Name three paint () methods which are used to paint Swing Component.

 protected void paintComponent(Graphics g)
 protected void paintBorder(Graphics g)
 protected void paintChildren(Graphics g)

Q. What will happen if class implemented WindowListner interface and provided its definition of only one method?

Answer:- To handle window events, we need to implement “WindowListner” interface. To handle window events, we need to implement “WindowListner” interface. “WindowListner” interface contains 7 methods We require only one i.e. windowClosing But, We have to provide definitions of all methods to make our class a concrete class, if don’t do this we can not create its object.

Q. Write Different between abstract class and interface class? 

Answer:-  Interfaces are essentially having all method prototypes no definition but Abstract class can contain method definitions also. When the sub-types behavior is totally different then you use an interface, when the sub-types behavior is partially common and different with respect to the super type an abstract class is used.

Q. Write 4 types of JDBC Driver. 


Type – 1: JDBC – ODBC Bridge

Type 2: Native – API/partly Java driver

Type 3: Net – protocol/all–Java driver

Type 4: Native – protocol/all–Java driver

Q. Why is directly paint component () method not recommended?

Answer:- Painting is managed by system, so calling paintComponent() directly is not recommended at all. Similarly calling paint( ) method is also not recommended. Why? Because such code may be invoked at times when it is not appropriate to paint — for instance, before the component is visible or has access to a valid Graphics object.

Q. Write a difference between execute query SQL and update query SQL method?

Answer:- executeQuery(sql) method
 Used for SQL SELECT queries
 Returns the ResultSET object that contains the results of the query and can be used to access the query results.
String sql = “SELECT * from sometable”;ResultSet rs =stmt.executeQuery(sql); executeUpdate(sql)method
 This method is used for executing an update statement like INSERT, UPDATE or DELETE
 Returns an integer value representing the number of rows updated
String sql = “INSERT INTO tablename ” + “(columnNames) Values (values)” ; int count = stmt.executeUpdate(sql);

Q. Is iterator class or interface? what is its use?

Answer:-  Iterator is an interface which is used to step through the elements of a Collection.

Q. Discuss three method of result set meta data.

Answer:- Useful ResultSetMetaData methods

getColumnCount ( )

– Returns the number of columns in the result set

getColumnDisplaySize (int)

Returns the maximum width of the specified column in characters

getColumnType(int) Returns the SQL type for the column to compare against types in java.sql.Types

Q.  How GUI Component handles 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.

Q. Which Component subclasses are used for paint.

Answer:- ‘Canvas’ is the subclass of Component that can be used for drawing and painting. But generally Graphics class and its methods are used for drawing and painting. They are quite familiar with Java developers for drawing and painting. Canvas and Graphics have some common methods that are inherited from Component like paint(),update() etc. but Graphics class provides more facilities to a programmer with its methods.

Q. What is port? how can it useful in network?

Answer:- It is a transport address to which processes can listen for connections request. There are different protocols available to communicate such as TCP and UDP. We will use TCP for programming in this handout.

Q.How do we load a driver and how do we define a connection for URL and JDBC.


Load Driver
 Need to load suitable driver for underlying database.
 Different drivers & types for different databases are available.
 For MS Access, load following driver available with j2se.
 For Oracle, load the following driver. You have to download it explicitly.

Define Connection URL

To get a connection, we need to specify the URL of a database (Actually we need to specify the address of the database which is in the form of URL) As we are using Microsoft Access database and we have loaded a JDBC-ODBC driver. Using JDBC-ODBC driver requires a DSN which we have created earlier and named it personDSN.

Q.Write the syntax of update SQL Query. 

Answer:- String sql = “INSERT INTO tablename ” + “(columnNames) Values (values)” ; int count = stmt.executeUpdate(sql);

Q. What is the difference between Applet and Application.

Answer:- Detail Applets as previously described, are the small programs while applications are larger programs. Applets don’t have the main method while in an application execution starts with the main method. Applets can run in our browser’s window or in an applet viewer. To run the applet in an applet viewer will be an advantage for debugging. Applets are designed for the client site programming purpose while the applications don’t have such type of criteria. Applet is the powerful tools because it covers half of the java language picture. Java applets are the best way of creating the programs in java. There are a less number of java programmers that have the hands on experience on java applications. This is not the deficiency of java applications but the global utilization of internet. It doesn’t mean that the java applications don’t have the place. Both (Applets and the java applications) have the same importance at their own places. Applications are also the platform independent as well as byte oriented just like the applets. Applets are designed just for handling the client site problems. while the java applications are designed to work with the client as well as server. Applications are designed to exist in a secure area. While the applets are typically used.

Q.Can an anonymous class be declared as implementing an inheritance and extending a class.

Answer:- No. An anonymous class can extend a class or implement an interface, but it cannot be declared to do both.

Q. Difference between serialization and de-serialization.

Answer:- Click here for Detail serialization – Turn data into a stream of bytes de-serialization – Turn a stream of bytes back into a copy of the original object.

Q. Difference between character oriented and byte oriented streams.

Answer:- Byte stream access the file byte by byte. A byte stream is suitable for any kind of file, however not quite appropriate for text files. For example, if the file is using a Unicode encoding and a character is represented with two bytes, the byte stream will treat these separately and you will need to do the conversion yourself. A character stream will read a file character by character. A character stream needs to be given the file’s encoding in order to work properly.

Q. If a method is declared as protected where can be the method accessed? 

Answer:- Accessible only to the class itself and to its subclasses or other classes in the same package.

Q. How can we prevent serialization? 


 Often there is no need to serialize sockets, streams & DB connections etc because they do no represent the state of object, rather connections to external resources
 To do so, transient keyword is used to mark a field that should not be serialized
 So we can mark them as,
o transient Socket s; o transient OutputStream os; o transient Connecction con;
 Transient fields are returned as nullon reading

Q. stages of applet cycles.

 It can initialize itself.
 It can start running.
 It can stop running.
 It can perform a final cleanup, in preparation for being unloaded

Q. How can you retrieve data from the ResultSet?

Answer:-  The JdbcEx.java demonstrates the usage of all above explained steps. In this code example, we connect with the PersonInfo database, the one we have created earlier, and then execute the simple SQL SELECT query on Person table, and then process the query results.

Q, Can applets communicate with each other?

Answer:- Applets may communicate with other applets running in the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the applets are of different classes, then each will need a reference to the same class with static variables. In any case the basic idea is to pass the information back and forth through a static variable. An applet can also get references to all other applets on the same page using the getApplets() method of java.applet.AppletContext. Once you got a reference to an applet, you can communicate with it by using its public members.

Q. As a developer of GUI, what should u know about top level containers and general purpose containers?

Answer:-  A container is a collection of related components, which allows other components to be nested inside it. In application with JFrame, we attatch components to the content pane – a container.

Container are classified into two broad categories that are Top Level containers and General Purpose Containers

Top level containers can contain (add) other containers as well as basic components (buttons, labels etc) while general purpose containers are typically used to collect basic components and are added to top level containers.

General purpose containers cannot exist alone they must be added to top level containers

Examples of top level container are JFrame, Dialog and Applet etc. Our application uses one of these. Examples of general purpose container are JPanel, Toolbar and ScrollPane etc.

Q.What is the difference between a static and a non-static inner class?

Answer: –  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 Anonymous object and Named object? Give example with code.

Answer:- We generally use anonymous object when there is just a one time use of a particular object but in case of a repeated use we generally used named objects and use that named reference to use that objects again and again.


– String s = “hello”; System.out.println(s);

– “hello” has a named reference s.

– System.out.println(“hello”);

Q. Why we use paintChildern( ) method?

Answer:- Tells any components contained by this component to paint themselves It is suggested that you do not override or invoke this method too.