Friday, February 2, 2007

What is the base class for all swing components ?

JComponent (except top-level containers)

SOURCE : www.referjava.com

What is Difference between AWT and Swing ?

Posted: Tue Jan 30, 2007 12:17 pm Post subject: What is Difference between AWT and Swing ?

--------------------------------------------------------------------------------

Swing provides a richer set of components than AWT. They are 100% Java-based. AWT on the other hand was developed with the mind set that if a component or capability of a component weren’t available on one platform, it wouldn’t be available on any platform. Due to the peer-based nature of AWT, what might work on one implementation might not work on another, as the peer-integration might not be as robust. There are a few other advantages to Swing over AWT:


Swing provides both additional components and added functionality to AWT-replacement components
Swing components can change their appearance based on the current "look and feel" library that's being used.
Swing components follow the Model-View-Controller (MVC) paradigm, and thus can provide a much more flexible UI.
Swing provides "extras" for components, such as:
Icons on many components
Decorative borders for components
Tool tips for components
Swing components are lightweight (less resource intensive than AWT)
Swing provides built-in double buffering
Swing provides paint debugging support for when you build your own components

Swing also has a few disadvantages:


It requires Java 2 or a separate JAR file
If you're not very careful when programming, it can be slower than AWT (all components are drawn)
Swing components that look like native components might not act exactly like native components


SOURCE : www.referjava.com

Why do you Canvas ?

The Canvas class of java.awt is used to provide custom drawing and event handling. It provides a general GUI component for drawing images and text on the screen. It does not support any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object associated with a Canvas object can be updated.


SOURCE : www.referjava.com

Why do you Canvas ?

The Canvas class of java.awt is used to provide custom drawing and event handling. It provides a general GUI component for drawing images and text on the screen. It does not support any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object associated with a Canvas object can be updated.


SOURCE : www.referjava.com

Why do you Canvas ?

The Canvas class of java.awt is used to provide custom drawing and event handling. It provides a general GUI component for drawing images and text on the screen. It does not support any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object associated with a Canvas object can be updated.


SOURCE : www.referjava.com

What are 4 drivers available in JDBC ?

Type 1: JDBC-ODBC Bridge
The type 1 driver, JDBC-ODBC Bridge, translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, in many cases, the client database code, must be present on the client machine. May be used when an ODBC driver has already been installed on client machine and performance is not an issue.
Type 2: Native-API/partly Java driver
JDBC driver type 2 -- the native-API/partly Java driver -- converts JDBC calls into database-specific calls for databases such as SQL Server, Informix, Oracle, or Sybase. The type 2 driver communicates directly with the database server; therefore it requires that some binary code be present on the client machine. Can be used when application is not for internet.
Type 3: Net-protocol/all-Java driver
JDBC driver type 3 -- the net-protocol/all-Java driver -- follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. If the middle-tier server is written in Java, it can use a type 1 or type 2 JDBC driver to do this.Type 3 drivers are best suited for environments that need to provide connectivity to a variety of DBMS servers and heterogeneous databases and that require significantly high levels of concurrently connected users where performance and scalability are major concerns.
Type 4: Native-protocol/all-Java driver
The native-protocol/all-Java driver (JDBC driver type 4) converts JDBC calls into the vendor-specific database management system (DBMS) protocol so that client applications can communicate directly with the database server. Level 4 drivers are completely implemented in Java to achieve platform independence and eliminate deployment administration issues. Useful for Internet-related applications.

SOURCE : www.referjava.com

Where the CardLayout is used ?

CardLayout manages two or more components that share the same display space. It lets you use one container (usually a panel) to display one out of many possible component children (like flipping cards on a table). A program can use this layout to show a different child component to different users. For example, the interface shown to an administrator might have additional functionality from the interface shown to a regular user. With card layout, our program can show the appropriate interface depending on the type of user using the program. Another typical use of card layout would be to let end user toggle among different displays and choose the one they prefer. In this case, the program must provide a GUI for the user to make the selection.

SOURCE : www.referjava.com

What is bean ? Where it can be used ?

A JavaBean is basically a Java class which satisfies a few simple rules (it must have a no-arg constructor, properties have getters and setters; actually, you can get around the last rule by supplying a BeanInfo object for your bean). JavaBeans were originally conceived for graphical application builder tools, but that emphasis has shifted considerably and they're now used almost everywhere.

SOURCE : www.referjava.com

What is difference in between Java Class and Bean ?

A Bean can have associated support classes: a BeanInfo class providing information about the bean, its properties and its events, and also property editors and a graphical customizer.

SOURCE : www.referjava.com

Can we send object using Sockets ?

Sure. Socket I/O is exposed at streams. We can send/receive objects to/from streams using serialization.

SOURCE : www.referjava.com

What is difference between Design Pattern and Framework?

A Framework is a skeleton of code used for developing an application with ease. It could have used several design patterns to implement the skeleton upon which we generally build applications. Eg. Struts Framework uses MVC2 architecture; various design patterns like Front- Controller, Composite, Command patterns.
Such design patterns used in the framework also helps to build applications with simplicity e.g.. Struts-config.xml makes your app configurable, resuable,fewer impacts on changes to functionality (Command pattern)Can go thru Struts architecture for further details.

SOURCE : www.referjava.com

What is difference between Design Pattern and Framework?

A Framework is a skeleton of code used for developing an application with ease. It could have used several design patterns to implement the skeleton upon which we generally build applications. Eg. Struts Framework uses MVC2 architecture; various design patterns like Front- Controller, Composite, Command patterns.
Such design patterns used in the framework also helps to build applications with simplicity e.g.. Struts-config.xml makes your app configurable, resuable,fewer impacts on changes to functionality (Command pattern)Can go thru Struts architecture for further details.

SOURCE : www.referjava.com

What is the use of findby primarykey ()?

The findByPrimaryKey () method works like the read () method, except that the findByPrimaryKey () method retrieves a single TX Object directly from the database using a primary key without going through a TX Cursor. The primary key can be any primary key. For example, RealmId is the official the realm name is unique; it can also be used as an alternate primary key to retrieve a realm.
You decide what the primary key will be. However, the object must exist, and it must be unique.
For example, to use the findByPrimaryKey () method to find subscribers using their daytime telephone numbers, you must ensure that each daytime telephone number is unique.
You can combine the findByPrimaryKey () method with the read (TX Object) method.

SOURCE : www.referjava.com

In which pattern does all the action classes in the struts ?

a. All the action classes the design pattern used is the Command Design Pattern
b. mvc design pattern
c. MVC-Model View Controller
Model-JSP
View-JSP
Controller-Servlet

SOURCE : www.referjava.com

What is the actual difference between MVC and MVC Model2?

a. MVC1 is architecture, which does not include struts framework in it, whereas in case of MVC2 it includes struts frame work. MVC1 is called model1 and MVC2 is called model2.

b. MVC1 is architecture, which does not include struts framework in it, whereas in case of MVC2 it includes struts frame work. MVC1 is called model1 and MVC2 is called model2.

c. In MVC1 architecture only one controller is responsible for both business logic and to send control for the other model components. Where as in MVC2 the business logic is separated from control components. And only one controller is responsible for taking all the requests and responses. And servlet acts as a controller.

d. Mvc is divided that our middle tier architecture should divide in three parts like model, view and controller. But it doesn’t know what are those components.
Where as model2 arch tells that model is Ejb/java bean, view is jsp, controller is servlet.

SOURCE : www.referjava.com

How can i pass info from dyna form bean to Entity Bean (CMP)

a) First you need to import Home Interface, Remote Interfaces into your bean, (.jar file should be placed in WEB-INF/lib folder) and then, you get access to the HomeOjbect using the Initial Context Object, and by passing dynamo form values to findByPrimaryKey () method you can forward info to ejb.

b) We can access dynaform bean information in action class after that calls ejb entity beans in execute method .use that entity beans and pass the information of form beans in create or findByprimarykey methods after use if u require.

SOURCE : www.referjava.com

How to build struts in java? What are the functions of struts?

To build struts in Java, we need the struts taglib. They provide many of the inbuilt tags that provide the many activities like loop, tiles (to beautify the page) etc. For this the struts.jarfile has to be in the class path. Any jsp engine will then apply the struts. This is mainly the web platform to develop the dynamic pages.

SOURCE : www.referjava.com

How to build struts in java? What are the functions of struts?

To build struts in Java, we need the struts taglib. They provide many of the inbuilt tags that provide the many activities like loop, tiles (to beautify the page) etc. For this the struts.jarfile has to be in the class path. Any jsp engine will then apply the struts. This is mainly the web platform to develop the dynamic pages.

SOURCE : www.referjava.com

When we are saving form bean, what is the difference between ?

a) When the scope is request, the values of form bean would be available for one the current request. When the scope is session, the values of form bean would be available throughout the session.

b) If you are using request scope the Action Form is available only until the end of the request/response cycle. One the response has been returned to the client the action form and the data within it are no Langer accessible. if u want to keep the form data around for langer than a single request your can fonfig an Acton form to have session scope.

SOURCE : www.referjava.com

How you save data across diff pgs for particluar client ?

a) Several ways. The similar to the ways session tracking is enabled. Using cookies, URL-rewriting, SSLSession, and possibility threw in the database.

b) If the request has a Form object, the data may be passed on through the Form object across pages. Or within the Action class, call request.getSession and use session.setAttribute (), though that will persist through the life of the session until altered.

SOURCE : www.referjava.com

What is the difference between Action Form and DynaActionForm?

a) In struts 1.0; action form is used to populate the html tags in jsp using struts custom tag. When the java code changes, the change in action class is needed. To avoid the changes in struts 1.1 dyna action form is introduced. This can be used to develop using xml. The dyna action form bloats up with the struts-config.xml based definition.

b) There is no need to write action form class for the DynaActionForm and all the variables related to the action form class will be specified in the struts-config.xml
Where as we have to create Action form class with getter and setter methods which are to be populated from the form.

SOURCE : www.referjava.com

What is Dispatch Action?

The Dispatch Action class is used to group related actions into one class. Dispatch Action is an abstract class, so you must override it to use it. It extends the Action class. It should be noted that you don’t have to use the Dispatch Action to group multiple actions into one Action class. You could just use a hidden field that you inspect to delegate to member () methods inside of your action.

SOURCE : www.referjava.com

What is the difference between Action Errors and Action Messages?

The difference between the classes is zero -- all behavior in Action Errors was pushed up into Action Messages and all behavior in Action Error was pushed up into Action Message. This was done in the attempt to clearly signal that these classes can be used to pass any kind of messages from the controller to the view -- errors being only one kind of message.

SOURCE : www.referjava.com

What about security?

Different directories have different ways of dealing with security. JNDI allows for applications to work in conjunction with directory-specific security systems. In the future, JNDI-based applications will be able to take advantage of any single sign-on mechanism developed for the Java platform.

SOURCE : www.referjava.com

How does JNDI relate to Netscape's Java LDAP API?

Netscape's API is LDAP-specific. It is used for low-level access to LDAP directories. It exposes details about the protocol that applications typically do not need to know.
JNDI is a generic directory API for Java programs. It is analogous to the java.io.File class for accessing files. There might be some administrative programs that need to manipulate a file at the protocol level (such as NFS), but typically all Java applications use the File class to access to file system. Similarly, most Java programs should use JNDI to access directories. Applications that need to manipulate directory content at the protocol level may choose to use Netscape's API.


SOURCE : www.referjava.com

How does JNDI relate to Netscape's Java LDAP API?

Netscape's API is LDAP-specific. It is used for low-level access to LDAP directories. It exposes details about the protocol that applications typically do not need to know.
JNDI is a generic directory API for Java programs. It is analogous to the java.io.File class for accessing files. There might be some administrative programs that need to manipulate a file at the protocol level (such as NFS), but typically all Java applications use the File class to access to file system. Similarly, most Java programs should use JNDI to access directories. Applications that need to manipulate directory content at the protocol level may choose to use Netscape's API.


SOURCE : www.referjava.com

How does JNDI relate to LDAP?

JNDI provides an excellent object-oriented abstraction of directory and naming. Developers using JNDI can produce queries that use LDAP or other access protocols to retrieve results; however, they are not limited to LDAP nor do they have to develop their applications wired to LDAP. JNDI supports the key capabilities in LDAP v3.

SOURCE : www.referjava.com

What protocols does JNDI provide an interface to?

JNDI itself is independent of any specific directory access protocol. Individual service providers determine the protocols to support. There will be provider implementations for popular protocols, such as LDAP, NDS, DNS, and NIS(YP), supplied by different vendors.


SOURCE : www.referjava.com

Who should use JNDI?

Any Java application that needs to access information about users, machines, networks, and services. User information includes security credentials, phone numbers, electronic and postal mail addresses, and application preferences. Machine information includes network addresses, machine configurations, etc. In addition, any Java application that needs to either export objects or access objects exported by other applications and services. Examples include printers, calendars, and networked file systems.

SOURCE : www.referjava.com

Is there a way to execute a JSP from the comandline

There is a little tool called JSPExecutor that allows you to do just that. The developers (Hendrik Schreiber & Peter Rossbach ) aim was not to write a full blown servlet engine, but to provide means to use JSP for generating source code or reports. Therefore most HTTP-specific features (headers, sessions, etc) are not implemented, i.e. no reponseline or header is generated. Nevertheless you can use it to precompile JSP for your website.

SOURCE : www.referjava.com

What is a Scriptlet?

A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.Within scriptlet tags, you can
1.Declare variables or methods to use later in the file (see also Declaration).

2.Write expressions valid in the page scripting language (see also Expression).

3.Use any of the JSP implicit objects or any object declared with a tag.
You must write plain text, HTML-encoded text, or other JSP tags outside the scriptlet.

Scriptlets are executed at request time, when the JSP engine processes the client request. If the scriptlet produces output, the output is stored in the out object, from which you can display it.


SOURCE : www.referjava.com

What is a Declaration?

A declaration 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 they are separated by semicolons. The declaration must be valid in the scripting language used in the JSP file.

<%! somedeclarations %>
<%! int i = 0; %>
<%! int a, b, c; %>


SOURCE : www.referjava.com

What is a Expression?

An expression tag contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. Because the value of an expression is converted to a String, you can use an expression within text in a JSP file. Like
<%= someexpression %>
<%= (new java.util.Date()).toLocaleString() %>
You cannot use a semicolon to end an expression

SOURCE : www.referjava.com

What is a Hidden Comment?

A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or "comment out" part of your JSP page.
You can use any characters in the body of the comment except the closing --%> combination. If you need to use --%> in your comment, you can escape it by typing --%\>.
JSP Syntax
<%-- comment --%>



SOURCE : www.referjava.com

What is a output comment?

A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.

JSP Syntax


Example 1


Displays in the page source:


SOURCE : www.referjava.com