Java Interview Questions -21

Java Interview Questions -21

1. What is the difference between JSP and Servlets ?

JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.

2. What is difference between custom JSP tags and beans?

Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag’s behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags
Custom tags and beans accomplish the same goals — encapsulating complex behavior into simple and accessible forms. There are several differences:

3. What are the different ways for session tracking?

Cookies, URL rewriting, HttpSession, Hidden form fields

4. What mechanisms are used by a Servlet Container to maintain session information?

Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

5. Difference between GET and POST

In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.
In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure.

6. What is session?

The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server.

7. What is servlet mapping?

The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.

8. What is servlet context ?

The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.

9. What is a servlet ?

servlet is a java program that runs inside a web container.

10. Can we use the constructor, instead of init(), to initialize servlet?

Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.

11.What Class.forName will do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

12. How many JSP scripting elements are there and what are they?

There are three scripting language elements: declarations, scriptlets, expressions.

13. How do I include static files within a JSP page?

Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.

14. How can I implement a thread-safe JSP page?

You can make your JSPs thread-safe adding the directive within your JSP page.

15. What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

16. What are the lifecycle of JSP?

When presented with JSP page the JSP engine does the following 7 phases.
Page translation: -page is parsed, and a java file which is a servlet is created.
Page compilation: page is compiled into a class file
Page loading : This class file is loaded.
Create an instance :- Instance of servlet is created
jspInit() method is called
_jspService is called to handle service calls
_jspDestroy is called to destroy it when the servlet is not required.

17. What are context initialization parameters?

Context initialization parameters are specified by the in the web.xml file, these are initialization parameter for the whole application.

18. What is a Expression?

Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. This will be included in the service method of the generated servlet.

19. What is a Declaration?

It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file. This will be included in the declaration section of the generated servlet.

20. What is a Scriptlet?

A scriptlet can contain any number of language statements, variable or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a . Generally a scriptlet can contain any java code that are valid inside a normal java method. This will become the part of generated servlet’s service method.

21.What is Servlet Context?

this object represents resources shared by a group of servlets like servlet's environment,
Application attributes shared in the context level.

22.How do you trap the debug the errors in servlets.

error log file

23.How do you debug the Servlet?

through servlet log();

24.How do u implement threads in servlet?

Intenally implemented

25.How do you access variables across the sessions.

Through ServletContext.

26.where the session data will store?

session objects

27.How do you handle DataBase access and in which method of the servlet do you like to create connection.

init()

28.What are the different servers available for developing and deploying Servlets?

a) JRun2.0--Allaire
b) Apache --jserv
c) jwsdk2.0 --sun
d) servletexec
e) Tomcat webserver--tomcat
f)Weblogic AS--BEA Systems
g)NetDynamics5.0--sun
h)Iplanet--sun&netscape
i)Netscape--netscape
g)IBM websphere--IBM
h)oracle--oracle
i)Proton-Pramati technologies

29.If you want to improve the performance how do you create connections for multiple users?

Connection Pooling.

30.what is connection pooling?

Class which manages no of user requests for connections to improve the performance.

31.Why should we go for interservlet communication?

Servlets running together in the same server communicate with each other in several ways.
The three major reasons to use interservlet communication are:
a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform
certain tasks (through the ServletContext object)
b) Servlet reuse - allows the servlet to reuse the public methods of another servlet.
c) Servlet collaboration - requires to communicate with each other by sharing specific information
(through method invocation)

32.Is it possible to call servlet with parameters in the URL?

Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).

33.What is Servlet chaining?

Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.
In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.

34.How do servlets handle multiple simultaneous requests?

The server has multiple threads that are available to handle requests. When a request comes in, it
is assigned to a thread, which calls a service method (for example: doGet(), doPost( ) and service( ) ) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.

35..How do I automatically reload servlets?

Depends upon the server's servlet reload properites.

36.What is JDBC?

JDBC may stand for Java Database Connectivity. It is also a trade mark. JDBC is a layer of abstraction
that allows users to choose between databases. It allows you to change to a different database engine
and to write to a single API. JDBC allows you to write database applications in Java without having to
concern yourself with the underlying details of a particular database.

37.Does the JDBC-ODBC Bridge support the new features in the JDBC 3.0 API?

The JDBC-ODBC Bridge provides a limited subset of the JDBC 3.0 API.

38.Can the JDBC-ODBC Bridge be used with applets?

Use of the JDBC-ODBC bridge from an untrusted applet running in a browser, such as Netscape
Navigator, isn't allowed. The JDBC-ODBC bridge doesn't allow untrusted code to call it for security
reasons. This is good because it means that an untrusted applet that is downloaded by the browser can't
circumvent Java security by calling ODBC. Remember that ODBC is native code, so once ODBC is called the Java programming language can't guarantee that a security violation won't occur. On the
other hand, Pure Java JDBC drivers work well with applets. They are fully downloadable and do not require any client-side configuration.Finally, we would like to note that it is possible to use the JDBC-ODBC bridge with applets that will be
run in appletviewer since appletviewer assumes that applets are trusted. In general, it is dangerous to turn applet security off, but it may be appropriate in certain controlled situations, such as for applets
that will only be used in a secure intranet environment. Remember to exercise caution if you choose this option, and use an all-Java JDBC driver whenever possible to avoid security problems.

39.What's the JDBC 3.0 API?

The JDBC 3.0 API is the latest update of the JDBC API. It contains many features, including scrollable
result sets and the SQL:1999 data types.
JDBC (Java Database Connectivity) is the standard for communication between a Java application and a relational database. The JDBC API is released in two versions; JDBC version 1.22 (released with JDK 1.1.X in package java.sql) and version 2.0 (released with Java platform 2 in packages java.sql and
javax.sql). It is a simple and powerful largely database-independent way of extracting and inserting data to or from any database.

40.How do I start debugging problems related to the JDBC API?

A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.
If you use the DriverManager facility to establish your database connection, you use the DriverManager.setLogWriter method to enable tracing of JDBC operations. If you use a DataSource
object to get a connection, you use the DataSource.setLogWriter method to enable tracing.

41.How can I use the JDBC API to access a desktop database like Microsoft Access over the
network?

Most desktop databases currently require a JDBC solution that uses ODBC underneath. This is because
the vendors of these database products haven't implemented all-Java JDBC drivers.
The best approach is to use a commercial JDBC driver that supports ODBC and the database you want to use. See the JDBC drivers page for a list of available JDBC drivers.
The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers
for desktop databases like Access aren't networked. The JDBC-ODBC bridge can be used together with the RMI-JDBC bridge, however, to access a desktop database like Access over the net. This RMIJDBC-
ODBC solution is free.

42.Are there any ODBC drivers that do not work with the JDBC-ODBC Bridge?

Most ODBC 2.0 drivers should work with the Bridge. Since there is some variation in functionality between ODBC drivers, the functionality of the bridge may be affected. The bridge works with popular
PC databases, such as Microsoft Access and FoxPro.

43.What causes the "No suitable driver" error?

"No suitable driver" is an error that usually occurs during a call to the DriverManager.getConnection
method. The cause can be failing to load the appropriate JDBC drivers before calling the getConnection
method, or it can be specifying an invalid JDBC URL--one that isn't recognized by your JDBC driver. Your best bet is to check the documentation for your JDBC driver or contact your JDBC driver vendor
if you suspect that the URL you are specifying is not being recognized by your JDBC driver.In addition, when you are using the JDBC-ODBC Bridge, this error can occur if one or more the the shared libraries needed by the Bridge cannot be loaded.
If you think this is the cause, check your configuration to be sure that the shared libraries are accessible to the Bridge.

44.What are the two major components of JDBC?

One implementation interface for database manufacturers, the other implementation interface for application and applet writers.

45.What is JDBC Driver interface?

The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided
by the JDBC API. Each vendor driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver.
How do I retrieve a whole row of data at once, instead of calling an individual ResultSet.

46.Which type of JDBC driver is the fastest one?

JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the jdbc calls into vendor
specific protocol calls and it directly interacts with the database. Are all the required JDBC drivers to establish connectivity to my database part of the JDK?
No. There aren't any JDBC technology-enabled drivers bundled with the JDK 1.1.x or Java 2 Platform releases other than the JDBC-ODBC Bridge. So, developers need to get a driver and install it before
they can connect to a database. We are considering bundling JDBC technology- enabled drivers in the future.

47.Is the JDBC-ODBC Bridge multi-threaded?

The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBCODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC.
Multithreaded Java programs may use the Bridge, but they won't get the advantages of multi-threading. In
addition, deadlocks can occur between locks held in the database and the semaphore used by the Bridge. We are thinking about removing the synchronized methods in the future. They were added
originally to make things simple for folks writing Java programs that use a single-threaded ODBC driver.

48.Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?

No. You can open only one Statement object per connection when you are using the JDBC-ODBC
Bridge.

49.What is the query used to display all tables names in SQL Server (Query analyzer)?

select * from information_schema.tables

50.Why can't I invoke the ResultSet methods afterLast and beforeFirst when the method next
works?

You are probably using a driver implemented for the JDBC 1.0 API. You need to upgrade to a JDBC
2.0 driver that implements scrollable result sets. Also be sure that your code has created scrollable result sets and that the DBMS you are using supports them.

51.How can I retrieve a String or other object type without creating a new object each time?

Creating and garbage collecting potentially large numbers of objects (millions) unnecessarily can really hurt performance. It may be better to provide a way to retrieve data like strings using the JDBC API without always allocating a new object.
We are studying this issue to see if it is an area in which the JDBC API should be improved. Stay tuned, and please send us any comments you have on this question.

52.How many types of JDBC Drivers are present and what are they?

There are 4 types of JDBC Drivers
Type 1: JDBC-ODBC Bridge Driver
Type 2: Native API Partly Java Driver
Type 3: Network protocol Driver
Type 4: JDBC Net pure Java Driver

53.What is the fastest type of JDBC driver?

JDBC driver performance will depend on a number of issues:
(a) the quality of the driver code,
(b) the size of the driver code,
(c) the database server and its load,
(d) network topology,
(e) the number of times your request is translated to a different API.
In general, all things being equal, you can assume that the more your request and response change
hands, the slower it will be. This means that Type 1 and Type 3 drivers will be slower than Type 2 drivers (the database calls are make at least three translations versus two), and Type 4 drivers are the
fastest (only one translation).

54.What is a statement? What are different types of it?

A statement is just like a vehicle which can be used to send SQL commands across the system. We can create various objects through the connection. We can also create statement kind of objects through this connection.
A statement is represented in such form-Statement stmt = conn.createStatement () ;
There are different types of statements, they are-
Prepared Statement
Callable Statement
An SQL statement that is pre-compiled with a database is known as a prepared statement. Through this process of compilation, the performance of SQL commands is increased considerably and prepared statements play a major role in it. Once it is compiled, such prepared statements can be customized according to the choice and can be altered with predefined SQL parameters.
Callable statements are used for invoking stored procedure and functions from JDBC applications.

55.What is a DriverManager?

A DriverManager is a category in java.sql package. It is a basic service which is provided for managing a set of JDBC drivers.

56.How to open a database connection?

A database connection is applied and practiced after registering the drivers. The getConnetction command is used to open a database connection. Here’s the coding procedure of opening a database-
Connection con;
con = DriverManager.getConnection(url,”scott”,”tiger”);// returns the connection object

57.What are the benefits of JDBC 4.0?

Here are few advantages of JDBC 4.0-Auto loading of JDBC driver class Connection management enhancements DataSet Implementation of SQL using annotations.
SQL XML support.

58.Is the JDBC-ODBC Bridge multi threaded?

No, the JDBC-ODBC Bridge is not in support of concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods and platforms to serialize all the commands it makes to ODBC. Multi threaded Java programs may use the Bridge, but they don’t get the advantages of multi-threading.

59. What are the basic steps of writing a Java program using JDBC?

Load the RDBMS specific JDBC driver, it will actually communicate with the database, but only if JDBC 4.0 is already installed.
Open the connection to database which is used for SQL statements. Then, create a JDBC statement object which contains SQL query.
Execute the statement which returns resultset(s), it contains the tuples of database as a result of SQL query.
Process the result set and close the connection

60.What are the main components of JDBC?

The life cycle of JDBC is- DriverManager> Driver> Connection> Statement> ResultSet.
The DriverManager is a list of database drivers available. It matched the connection requests from the Java application with the proper databse driver using apt communication sub protocol.
Connection interface with all the methods for containing a database.Statement consists of SQL statement which is passed to the database to be compiled, and executed.
The ResultSet represents set of two rows retrieved due to a query execution.

61.How do I use a scriptlet to initialize a newly instantiated bean?

A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone.
The following example shows the "today" property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action.
value=""/ >

62.How can I set a cookie and delete a cookie from within a JSP page?

A cookie, mycookie, can be deleted using the following scriptlet:

63.How do you connect to the database from JSP?

A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets.
Further then you can use the resultset object "res" to read data in the following way.
What is the page directive is used to prevent a JSP page from automatically creating a session?
<%@ page session="false">

64.How do you delete a Cookie within a JSP?

Cookie mycook = new Cookie("name","value");
response.addCookie(mycook);
Cookie killmycook = new Cookie("mycook","value");
killmycook.setMaxAge(0);
killmycook.setPath("/");
killmycook.addCookie(killmycook);

65.Can we implement an interface in a JSP?

No

66.What is the difference between ServletContext and PageContext?

ServletContext: Gives the information about the container
PageContext: Gives the information about the Request

67.What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource.

68.How to pass information from JSP to included JSP?

Using <%jsp:param> tag.

69.How is JSP include directive different from JSP include action. ?

When a JSP include directive is used, the included file's code is added into the added JSP page at page translation time, this happens before the JSP page is translated into a servlet. While if any page is included using action tag, the page's output is returned back to the added page. This happens at runtime.

70.Can we override the jspInit(), _jspService() and jspDestroy() methods?

We can override jspinit() and jspDestroy() methods but not _jspService().

71.Why is _jspService() method starting with an '_' while other life cycle methods do not?

_jspService() method will be written by the container hence any methods which are not to be overridden by the end user are typically written starting with an '_'. This is the reason why we don't override _jspService() method in any JSP page.

72.What happens when a page is statically included in another JSP page?

An include directive tells the JSP engine to include the contents of another file (HTML, JSP, etc.) in the current page. This process of including a file is also called as static include.

73.A JSP page, include.jsp, has a instance variable "int a", now this page is statically included in another JSP page, index.jsp, which has a instance variable "int a" declared. What happens when the index.jsp page is requested by the client?

Compilation error, as two variables with same name can't be declared. This happens because, when a page is included statically, entire code of included page becomes part of the new page. at this time there are two declarations of variable 'a'. Hence compilation error

74.What is the difference between Integer and int?

Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.

75.What is a cloneable interface and how many methods does it contain?

It is not having any method because it is a TAGGED or MARKER interface.

76.What is the difference between abstract class and interface?

All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.

77.What is the difference between String and String Buffer?

a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.

78.What is the difference between Array and vector?

Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.

79.What is the difference between exception and error?

The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.

80.What is the difference between process and thread?

Process is a program in execution whereas thread is a separate path of execution in a program.

81.What is multithreading and what are the methods for inter

thread communication and what is the class in which these methods are defined?- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.

82.What is the class and interface in java to create thread and which is the most advantageous method?

Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

83.What are the states associated in the thread?

Thread contains ready, running, waiting and dead states.

84.What is synchronization?

Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.

85.When you will synchronize a piece of your code?

When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.

86.What is deadlock?

When two threads are waiting each other and can’t precede the program is said to be deadlock.

87.What is daemon thread and which method is used to create the daemon thread?

Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
Are there any global variables in Java, which can be accessed by other part of your program?- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.

88.What is an applet?

Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.

89.What is the difference between applications and applets?

a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.

90.How does applet recognize the height and width?

Using getParameters() method.

91.When do you use codebase in applet?

When the applet class file is not in the same directory, codebase is used.

92.What is the lifecycle of an applet?

init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.

93.How do you set security in applets?

using setSecurityManager() method

94.What is an event and what are the models available for event handling?

An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model

95.What are the advantages of the model over the event-inheritance model?

The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)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 be repeatedly process unhandled events as is the case of the event-inheritance.

96.What is source and listener?

source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.

97.What is adapter class?

An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .

98.What is the difference between JDBC and ODBC?-

a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.

99.What are the types of JDBC Driver Models and explain them?

There are two types of JDBC Driver Models and they are: a) Two tier model and b) Three tier model Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server. Three tier model: A middle tier is introduced in this model. The functions of this model are: a) Collection of SQL statements from the client and handing it over to the database, b) Receiving results from database to the client and c) Maintaining control over accessing and updating of the above.

100.What is meant by controls and what are different types of controls in AWT?

Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.

101.What is the difference between choice and list?

A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.

102.What is the difference between scrollbar and scrollpane?

A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.

103.What is a layout manager and what are different types of layout managers available in java AWT?

A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.

104.How are the elements of different layouts organized?

FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

105.Which containers use a Border layout as their default layout?

Window, Frame and Dialog classes use a BorderLayout as their layout.

106.What are wrapper classes?

Wrapper classes are classes that allow primitive types to be accessed as objects.

107.What are Vector, Hashtable, LinkedList and Enumeration?

Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.

108.What is the difference between set and list?

Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.

109.What is a stream and what are the types of Streams and classes of the Streams?

A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are: Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input & output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.

110.What is the difference between Reader/Writer and InputStream/Output Stream?

The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.



-------------------------------------
Also Read:






































 

0 comments:

Post a Comment