- Easy to use APIs for developing web service clients.
- Mix scripting and Java in your code. Javascript comes as standard, you can add many more languages.
- Updated JDBC 4.0 APIs, and an all-Java JDBC database included in the JDK.
- Programmatically control the javac compiler.
- Define your own annotations and plug in the code to process them.
- Double digit improvements in performance, client and server. 100,000+ tests for compatibility alone.
Tuesday, November 20, 2007
Monday, November 19, 2007
Sunday, November 18, 2007
SQL
AND / OR
SELECT column_name(s)FROM table_nameWHERE conditionANDOR condition
ALTER TABLE (add column)
ALTER TABLE table_name ADD column_name datatype
ALTER TABLE (drop column)
ALTER TABLE table_name DROP COLUMN column_name
AS (alias for column)
SELECT column_name AS column_aliasFROM table_name
AS (alias for table)
SELECT column_nameFROM table_name AS table_alias
BETWEEN
SELECT column_name(s)FROM table_nameWHERE column_nameBETWEEN value1 AND value2
CREATE DATABASE
CREATE DATABASE database_name
CREATE INDEX
CREATE INDEX index_nameON table_name (column_name)
CREATE TABLE
CREATE TABLE table_name(column_name1 data_type,column_name2 data_type,.......)
CREATE UNIQUE INDEX
CREATE UNIQUE INDEX index_nameON table_name (column_name)
CREATE VIEW
CREATE VIEW view_name ASSELECT column_name(s)FROM table_nameWHERE condition
DELETE FROM
DELETE FROM table_name (Note: Deletes the entire table!!)
or
DELETE FROM table_nameWHERE condition
DROP DATABASE
DROP DATABASE database_name
DROP INDEX
DROP INDEX table_name.index_name
DROP TABLE
DROP TABLE table_name
GROUP BY
SELECT column_name1,SUM(column_name2)FROM table_nameGROUP BY column_name1
HAVING
SELECT column_name1,SUM(column_name2)FROM table_nameGROUP BY column_name1HAVING SUM(column_name2) condition value
IN
SELECT column_name(s)FROM table_nameWHERE column_nameIN (value1,value2,..)
INSERT INTO
INSERT INTO table_nameVALUES (value1, value2,....)
or
INSERT INTO table_name(column_name1, column_name2,...)VALUES (value1, value2,....)
LIKE
SELECT column_name(s)FROM table_nameWHERE column_nameLIKE pattern
ORDER BY
SELECT column_name(s)FROM table_nameORDER BY column_name [ASCDESC]
SELECT
SELECT column_name(s)FROM table_name
SELECT *
SELECT *FROM table_name
SELECT DISTINCT
SELECT DISTINCT column_name(s)FROM table_name
SELECT INTO(used to create backup copies of tables)
SELECT *INTO new_table_nameFROM original_table_name
or
SELECT column_name(s)INTO new_table_nameFROM original_table_name
TRUNCATE TABLE(deletes only the data inside the table)
TRUNCATE TABLE table_name
UPDATE
UPDATE table_nameSET column_name=new_value[, column_name=new_value]WHERE column_name=some_value
WHERE
SELECT column_name(s)FROM table_nameWHERE condition
JAXBContext
Class JAXBContext
java.lang.Object
javax.xml.bind.JAXBContext
- public abstract class JAXBContext
- extends java.lang.Object
The JAXBContext class provides the client's entry point to the JAXB API. It provides an abstraction for managing the XML/Java binding information necessary to implement the JAXB binding framework operations: unmarshal, marshal and validate. A client application obtains new instances of this class via the newInstance(contextPath) method.
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
The contextPath contains a list of Java package names that contain schema derived interfaces. The value of this parameter initializes the JAXBContext object so that it is capable of managing the schema derived interfaces.
SPEC REQUIREMENT: the provider must supply an implementation class containing a method with the following signature:public static JAXBContext createContext( String contextPath, ClassLoader classLoader )
throws JAXBException;JAXB Providers must generate a jaxb.properties file in each package containing schema derived classes. The property file must contain a property named javax.xml.bind.context.factory whose value is the name of the class that implements the createContext API.
The class supplied by the provider does not have to be assignable to javax.xml.bind.JAXBContext, it simply has to provide a class that implements the createContext API.
In addition, the provider must call the
DatatypeConverter.setDatatypeConverterapi prior to any client invocations of the marshal and unmarshal methods. This is necessary to configure the datatype converter that will be used during these operations.
Unmarshalling
TheUnmarshallerclass provides the client application the ability to convert XML data into a tree of Java content objects. The unmarshal method for a schema (within a namespace) allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document. The JAXBContext object allows the merging of global elements across a set of schemas (listed in the contextPath). Since each schema in the schema set can belong to distinct namespaces, the unification of schemas to an unmarshalling context should be namespace independent. This means that a client application is able to unmarshal XML documents that are instances of any of the schemas listed in the contextPath. For example:JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
Unmarshaller u = jc.createUnmarshaller();
FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPathThe client application may also generate Java content trees explicitly rather than unmarshalling existing XML data. To do so, the application needs to have access and knowledge about each of the schema derived ObjectFactory classes that exist in each of java packages contained in the contextPath. For each schema derived java class, there will be a static factory method that produces objects of that type. For example, assume that after compiling a schema, you have a package com.acme.foo that contains a schema derived interface named PurchaseOrder. In order to create objects of that type, the client application would use the factory method like this:
com.acme.foo.PurchaseOrder po =
com.acme.foo.ObjectFactory.createPurchaseOrder();Once the client application has an instance of the the schema derived object, it can use the mutator methods to set content on it.
For more information on the generated ObjectFactory classes, see Section 4.2 Java Package of the specification.
SPEC REQUIREMENT: the provider must generate a class in each package that contains all of the necessary object factory methods for that package named ObjectFactory as well as the static newInstance( javaContentInterface ) method
Marshalling
TheMarshallerclass provides the client application the ability to convert a Java content tree back into XML data. There is no difference between marshalling a content tree that is created manually using the factory methods and marshalling a content tree that is the result an unmarshal operation. Clients can marshal a java content tree back to XML data to a java.io.OutputStream or a java.io.Writer. The marshalling process can alternatively produce SAX2 event streams to a registered ContentHandler or produce a DOM Node object.Here is a simple example that unmarshals an XML document and then marshals it back out:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
// unmarshal from foo.xml
Unmarshaller u = jc.createUnmarshaller();
FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
// marshal to System.out
Marshaller m = jc.createMarshaller();
m.marshal( fooObj, System.out );
Validation
There are three varieties of validation available to JAXB client applications:
- Unmarshal-time Validation
- Validation performed on the XML data as it is being unmarshalled into a Java content tree
- On-Demand Validation
- Validation performed on the Java content tree in memory
- Fail-Fast Validation
- Validation of Java property constraints at runtime when client applications invoke the setter methods of the generated classes
See: Validator javadocs for a more detailed definition of the different type of validation.
Although unmarshal-time validation and on-demand validation are very similar, they are completely orthogonal operations with no dependencies on each other. Client applications are free to use one, both, or neither types of validation.
Validation errors and warnings encountered during the unmarshal and validate operations are reported to the client application via a callback error handler interface (
ValidationEventHandler) that receivesValidationEventobjects. The ValidationEvent objects contain information about the error or warning encountered. JAXB allows a few diffent methods of handling validation events which are described in more detail in the Validator javadoc.
JAXB Runtime Binding Framework Compatibility
Since the JAXB Specification does not define a common runtime system, a JAXB client application must not attempt to mix runtime objects (JAXBContext, Marshaller, etc. ) from different providers. This does not mean that the client application isn't portable, it simply means that a client has to use a runtime system provided by the same provider that was used to compile the schema.
Dynamic sorting
public class BeanPropertyComparator implements Comparator {
private String property;
private Comparator comparator;
public BeanPropertyComparator(String property, Comparator comparator) {
this.property = property;
this.comparator = comparator;
}
public int compare(Object bean1, Object bean2) {
// Get the value of the properties
Object value1 = BeanPropertyUtil.getProperty(property,bean1);
Object value2 = BeanPropertyUtil.getProperty(property,bean2);
return comparator.compare(value1,value2);
}
}
Friday, November 16, 2007
JAVA URL's
EMACS -linux
Perl home page tutorials
regular expressions
VI editor
fast web browsing with caching proxy
LINUXLINUX ADMIN
Java Articles
jpcap" network analyser
NIO resources from IBM
Java programming dynamics, Part 3: Applied reflection
Data Binding with JAXB
Java threadingCollections
JDO's
JMSJava SocketsJava Class loader
Wednesday, November 14, 2007
JSF questions
AJAX questions
Java questions
example program below loops through any arguments passed to the program on the command line and lists their values.
More details available to subscribers:How can I write a program that takes command line input?
Q: What does public static void main(String[]) mean? A: This is a special static method signature that is used to run Java programs from a command line interface (CLI). There is nothing special about the method itself, it is a
standard Java method, but the Java interpreter is designed to call this method when a class reference is given on the command line, as below.
More details available to subscribers:What does public static void main(String[]) mean?
Q: Why are command line arguments passed as a String? A: Command line arguments are passed to the application's main method by the Java runtime system before the application class or any supporting objects are instantiated.
It would be much more complex to define and construct arbitrary object types to pass to the main method and primitive values alone are not versatile enough to provide the
range of input data that strings can. String arguments can be parsed for primitive values and can also be used for arbitrary text input, file and URL references.
Q: Why doesn't the main method throw an error with no arguments? A: When you invoke the Java Virtual Machine on a class without any arguments, the class' main method receives a String array of zero length. Thus, the method signature
is fulfilled. Provided the main method does not make any reference to elements in the array, or checks the array length before doing so, no exception will occur.
Q: Why do we only use the main method to start a program? A: The entry point method main is used to the provide a standard convention for starting Java programs. The choice of the method name is somewhat arbitrary, but is partly
designed to avoid clashes with the Thread start() and Runnable run() methods, for example.
Q: Can the main method be overloaded? A: Yes, any Java method can be overloaded, provided there is no final method with the same signature already. The Java interpreter will only invoke the standard entry point
signature for the main method, with a string array argument, but your application can call its own main method as required.
Main method modifiers Q: Can the main method be declared final? A: Yes, the static void main(String[]) method can be declared final.
Q: I get an exception if I remove the static modifier from main! A: The static void main(String[]) method is a basic convention of the Java programming language that provides an entry point into the runtime system. The main method must
be declared static because no objects exist when you first invoke the Java Virtual Machine (JVM), so there are no references to instance methods. The JVM creates the
initial runtime environment in which this static method can be called, if you remove the static modifier, it will throw a NoSuchMethodException.
Application start up Q: How can the static main method use instance variables? A: For very simple programs it is possible to write a main method that only uses static variables and methods. For more complex systems, the main method is used to
create an instance of itself, or another primary class, as the basis of the application. The primary application object reference uses instance methods to create and interact
with other objects, do the work and return when the application terminates.
public class SimpleClass {
public void doSomething() {
// Instance method statements }
public static main(final String[] args) {
SimpleClass instance = new SimpleClass();
instance.doSomething(); }} Q: Can I invoke the main method from another class? A: Yes, the main method can be called from a separate class. First you must prepare the string array of arguments to pass to the method, then call the method through a
static reference to the host class, MaxFactors in the example below.
String[] arguments = new String[] {"123"};
MaxFactors.main(arguments);
Concurrent programming features Q: What is threaded programming and when is it used? A: Threaded programming is normally used when a program is required to do more than one task at the same time. Threading is often used in applications with graphical
user interfaces; a new thread may be created to do some processor-intensive work while the main thread keeps the interface responsive to human interaction.
The Java programming language has threaded programming facilities built in, so it is relatively easy to create threaded programs. However, multi-threaded programs
introduce a degree of complexity that is not justified for most simple command line applications.
Q: Why are wait(), notify() and notifyall() methods defined in the Object class? A: These methods are detailed on the Java Software Development Kit JavaDoc page for the Object class, they are to implement threaded programming for all subclasses of
Object.
Q: Why are there separate wait and sleep methods? A: The static Thread.sleep(long) method maintains control of thread execution but delays the next action until the sleep time expires. The wait method gives up control over
thread execution indefinitely so that other threads can run.
More details available to subscribers:Why are there separate wait and sleep methods?
Threads and runnable types Q: What's the difference between Thread and Runnable types? A: A Java Thread controls the main path of execution in an application. When you invoke the Java Virtual Machine with the java command, it creates an implicit thread in
which to execute the main method. The Thread class provides a mechanism for the first thread to start-up other threads to run in parallel with it.
The Runnable interface defines a type of class that can be run by a thread. The only method it requires is run, which makes the interface very easy to to fulfil by extending
existing classes. A runnable class may have custom constructors and any number of other methods for configuration and manipulation.
Q: How does the run() method in Runnable work? A: It may help to think of the run method like the main method in standard single threaded applications. The run method is a standard entry point to run or execute a class.
The run method is normally only executed in the context of an independent Thread, but is a normal method in all other respects.
More details available to subscribers:How does the run() method in Runnable work?
Q: A Thread is runnable, how does that work? A: The Thread class' run method normally invokes the run method of the Runnable type it is passed in its constructor. However, it is possible to override the thread's run
method with your own.
More details available to subscribers:A Thread is runnable, how does that work?
Q: Why not override Thread to make a Runnable? A: There is little difference in the work required to override the Thread class compared with implementing the Runnable interface, both require the body of the run() method.
However, it is much simpler to make an existing class hierarchy runnable because any class can be adapted to implement the run() method. A subclass of Thread cannot
extend any other type, so application-specific code would have to be added to it rather than inherited.
Separating the Thread class from the Runnable implementation also avoids potential synchronization problems between the thread and the run() method. A separate
Runnable generally gives greater flexibility in the way that runnable code is referenced and executed.
Q: What's the difference between a thread's start() and run() methods? A: The separate start() and run() methods in the Thread class provide two ways to create threaded programs. The start() method starts the execution of the new thread and
calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns.
The Thread class' run() method does nothing, so sub-classes should override the method with code to execute in the second thread. If a Thread is instantiated with a
Runnable argument, the thread's run() method executes the run() method of the Runnable object in the new thread instead.
Depending on the nature of your threaded program, calling the Thread run() method directly can give the same output as calling via the start() method, but in the latter case
the code is actually executed in a new thread.
Q: Can I implement my own start() method? A: The Thread start() method is not marked final, but should not be overridden. This method contains the code that creates a new executable thread and is very specialised.
Your threaded application should either pass a Runnable type to a new Thread, or extend Thread and override the run() method.
Multi-threaded design questions Q: Do I need to use synchronized on setValue(int)? A: It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be
confined by the method and is not prone to threading issues.
More details available to subscribers:Do I need to use synchronized on setValue(int)?
Q: How do I create a Runnable with inheritance? A: To introduce a Runnable type to an existing class hierarchy, you need to create a sub-class that declares that it implements the Runnable interface, and provide a run
method to fulfil the interface. This combination of interface and inheritance means that runnable implementations can be very minor extensions of existing classes, as in the
example below...
More details available to subscribers:How do I create a Runnable with inheritance?
Q: What is the SwingUtilities.invokeLater(Runnable) method for? A: The static utility method invokeLater(Runnable) is intended to execute a new runnable thread from a Swing application without disturbing the normal sequence of event
dispatching from the Graphical User Interface (GUI). The method places the runnable object in the queue of Abstract Windowing Toolkit (AWT) events that are due to be
processed and returns immediately. The runnable object's run() method is only called when it reaches the front of the queue.
The deferred effect of the invokeLater(Runnable) method ensures that any necessary updates to the user interface can occur immediately, and the runnable work will begin
as soon as those high priority events are dealt with. The invoke later method might be used to start work in response to a button click that also requires a significant change
to the user interface, perhaps to restrict other activities, while the runnable thread executes.
Q: What is the volatile modifier for? A: The volatile modifier is used to identify variables whose values should not be optimized by the Java Virtual Machine, by caching the value for example. The volatile modifier
is typically used for variables that may be accessed or modified by numerous independent threads and signifies that the value may change without synchronization.
Q: Which class is the wait() method defined in? A: The wait() method is defined in the Object class, which is the ultimate superclass of all others. So the Thread class and any Runnable implementation inherit this method
from Object. The wait() method is normally called on an object in a multi-threaded program to allow other threads to run. The method should should only be called by a
thread that has ownership of the object's monitor, which usually means it is in a synchronized method or statement block.
More details available to subscribers:Which class is the wait() method defined in?
Thread programming jargon Q: What is a green thread? A: A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has
any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads.
There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from
more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.
Multi-threaded design patterns Q: What is a working thread? A: A working thread, more commonly known as a worker thread is the key part of a design pattern that allocates one thread to execute one task. When the task is
complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method
argument, typically execute(Runnable). The runnable tasks are usually stored in a queue until a thread host is available to run them.
The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated
with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires
relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.
Can I use a Javascript file stored as .jds? A: On the Web, the file extension you use for Javascript is not as important as the Content-Type header it is served with. With Apache, add this line to your .htaccess
configuration file:
AddType "application/x-javascript; charset=iso-8859-1" jds It is certainly best to separate your Javascript from your HTML like this in most cases. Firstly, it makes the script easier to edit and maintain, and means that any
number of HTML pages can reference the same script. Normally, a shared external script will only be downloaded once for each visitor, which speeds up delivery of your
page.
Javascript problems Q: My Javascript code is showing! A: It is conventional to put HTML comments around Javascript element content to hide it from browsers, like so ...
More details available to subscribers:My Javascript code is showing!
Q: I can't get your script to work! A: One of the key steps in externalising scripts is to ensure that all script file references are accurate.
Is the external file reference correct?The Code Style site uses relative URL paths with a leading forward slash, /; this means the URL is relative to the root level of the domain, not the current directory. If you are
adapting Code Style examples on a local file system, you will need to change these file references accordingly.
The following examples use stylesheet references, but the same conditions apply to all external files including scripts and images.
./Style.css Refers to the file Style.css in same directory as the HTML source, the "current" directory. styles/Style.css Refers to the file Style.css in a subdirectory of the current directory called styles. ../styles/Style.css Refers to the file Style.css in a directory called styles at the same hierarchical level as the current directory, i.e. in parallel to it. Has the script file loaded?To check if an external script file has loaded, add the following code to the top of the file and reload the HTML:
// Debuggingalert('Script loaded.'); This should raise a visible dialogue box if the script loads (you may need to clear your browser's cache to force a reload). Once you're sure the script has loaded, put
other temporary alerts into the script to find out which parts execute and which fail.
Q: I can't get Javascript to check for null strings correctly! A: It would help to see a fragment of the code. One thing to watch out for is the use of a single assignment equals instead of the double comparison equals...
More details available to subscribers:I can't get Javascript to check for null strings correctly!
Q: I get "Done, but with errors on page" in IE! A: The message "Done, but with errors on page" is an Internet Explorer error message that means there was a problem with one or more of the Javascript statements on the
page. Normally you will see a warning icon alongside the error message in the status bar. If you double click on the icon, a status message will open to give details of the
problem, which may help you fix the errors.
Working with dates in Javascript Q: How do I get the difference between two dates in Javascript? A: There are two elements to this question, first to find the difference between two dates and second to format the result. The code below creates three variables to represent
time intervals in milliseconds, then creates two dates with specific times on the same day. This could be adapted for any two dates, including the current time using the
basic Date() constructor.
More details available to subscribers:How do I get the difference between two dates in Javascript?
Q: How can I add 7 days to a date in Javascript? A: The example below creates a new Date object and a set of constants to calculate the number of milliseconds in 7 days. The 7 day figure is added to the original time and
used to create a second Date object.
More details available to subscribers:How can I add 7 days to a date in Javascript?
File security constraints Q: Can I get the file size on the client side? A: It is not possible to access files on a person's computer using Javascript through a Web browser, or to read the properties of files. It would be a serious security and
privacy hazard if Javascript code in a Web page could read files on your computer because the information could be sent back to the site via a form or other mechanisms.
For these reasons the possibility of file access was excluded when the Javascript language was designed.
Other client side solutions such as ActiveX and Java applets require special security consent from the user, which many people are reluctant to grant, and only make the job
more complicated and risky from their point of view. Not all Web browsers are configured to support ActiveX or Java.
The only effective way to check the size of a file for upload is on the server side. Your server side form handler must process the file and this is the best place to apply a limit
to the number of bytes you will accept.
Q: How can I create a file on the client side? A: It is not possible to create files on the client's computer using Javascript. This type of action is excluded from the Javascript language because it would be a serious
security hazard. The only form of local file storage available through Javascript is cookies, whose behaviour and contents are strictly prescribed.
Of course it is possible to use Javascript to generate file content in a Web browser window and invite people to save the contents. Internet Explorer and Firefox users can
use the File menu Save as... option directly, but Opera and other browser users may have to copy the text into another application to save it.
More details available to subscribers:How can I create a file on the client side?
Window and frame communication Q: Can I get the URL of any other browser window? A: Web browsers' Window object references only extend as far as windows in the same frameset or "child" windows spawned from a specific document. It would be a user
security violation if a script could read any other window's URL because this information could be communicated back to the script's host. For instance, you could append
the URL to the query parameter of a second page on the script's host, redirect to that URL and log or process the request.
What are your general guidelines about CSS? A: One of the key issues for authoring stylesheets is to be aware of the complex variety of software and hardware combinations and configurations that people use on the
Web, and concede that you cannot predict or ultimately control the way your documents are presented to users. Therefore it is vital that the underlying markup of your HTML
document makes sense without CSS.
Unless there is an exceptional case, and with font-size in particular, use proportional length values in stylesheets for the Web, preferably percentages % or em values.
Proportional values allow Web documents to scale relative to users' browser settings and screen resolution. Wherever you specify a color property, also specify a suitable, contrasting background property and vice-versa. This helps ensure that if the user has specified any personal
style settings, your document should still be legible. Many HTML elements do not strictly require a close tag, but it is important to explicitly close all relevant elements to optimise CSS rendering with certain browsers. Q: What is "presentational markup"? A: The most common example of HTML used primarily for presentational effect is the font element, which may specify the font family, size and colour of text on screen.
Other textual examples include big, small, b and i elements, or the link, background, vlink and alink attributes of the body element.
More details available to subscribers:What is "presentational markup"?
Q: Where can I find out more about CSS? A: The primary source of answers to frequently asked questions about CSS is the comp.infosystems.www.authoring.stylesheets (C.I.W.A.S) newsgroup FAQ.
CSS techniques Q: Has the stylesheet loaded? To check if an external stylesheet file has loaded, add an extreme style rule to make it obvious and reload the HTML:
BODY{ color: black; background: red;} Q: How can I hide my CSS? A: It is not possible for you to prevent read access to CSS files on the server side and have client browsers render the stylesheet. The browser must be able to download a
CSS file to render the styles it contains, this is the nature of the Web. The only way to prevent others viewing your CSS is not to publish it at all.
Q: Can I resize a whole site with CSS? A: If the site was designed for a fixed size then it may be quite difficult to adjust. If the widths of the page elements are set exclusively in the CSS, not in HTML tables, you
may be in with a chance; it would make the job easier. But the standard markup of the page may be the limiting factor. If the document markup is too rigid, you may need to
go back to the drawing board.
One quick way to get the measure of a Web site is to switch off CSS in your browser and see how it looks (see CSS browser configuration). If the navigation bars run down
the page and the text is full width when CSS is switched off, you may be in luck.
Q: Can I use script variables in my CSS? A: Yes, you can use an ASP, JSP or other scripting mechanisms to customise a style sheet, but you must serve it with the right HTTP Content-Type header: text/css.
Also, bear in mind that what you serve one person, may be held in shared caches and viewed by other people too. So, to ensure that everybody else gets the default style
sheet settings, you should also set no-cache headers.
If you prevent caches from storing your style sheet, it puts a heavier load on your Web server and will slow down every page request, which defeats one of the great
strengths of CSS.
Q: How can I block overrides from another stylesheet? A: CSS is implemented in a way that applies a style sheet to the whole of a Web document; specific style rules are attached to page elements based on selectors. One
style sheet cannot "block" part of another, but you can override a style rule with a more specific selector.
More details available to subscribers:How can I block overrides from another stylesheet?
CSS syntax and markup Q: How can I combine a style rule with HTML code? A: To apply so called "inline" styles, use the style attribute of the element you want to style.
Paragraph text
This technique can be useful when experimenting with new designs, but defeats one of the great strengths of CSS, using an external stylesheet to apply the samestyles to any number of pages.
Q: How can I combine style rules with each other? A: It is not possible to combine rules in a CSS stylesheet, but you can assign multiple classes to a single element in a space separated list...
More details available to subscribers:How can I combine style rules with each other?
Q: How do I remove underlines from links in my pop-ups? A: General usability advice is that people expect hyperlinks to be underlined, so your navigation may be overlooked if they are not. If you disable underlines, you should use
text and colours to make the links as conspicuous as possible.
Where you use dynamic markup techniques to create whole Web pages, such as pop-up windows, you must ensure that the HTML includes valid references to your
cascading style sheets. You must add a head element to the HTML root element and all necessary link elements, as below.
More details available to subscribers:How do I remove underlines from links in my pop-ups?
Q: What does the selector #content do? A: The selector #content matches any element with the id attribute "content", as below:
Table of contents
More details available to subscribers:What does the selector #content do?CSS styling tips Q: How do I set the background colour in CSS? A: When you set the background colour of a Web page using CSS you should also set the text colour, to ensure that there is a legible contrast between them. This is
because some people configure their browsers to display Web pages with their own style sheet, which may have its own text colour setting. If you set the background colour
without the text colour, your background may be the same as the reader's foreground text colour.
The background colour for the whole page is attached to the HTML body element, as below, but you can use any CSS selector to colour more specific areas of the page.
More details available to subscribers:How do I set the background colour in CSS?
Q: How do I style list elements? A: List items can be selected in CSS using the li element selector. It is also possible to select and style items in un-ordered lists independently from those in ordered lists,
and style specific items, as below.
More details available to subscribers:How do I style list elements?
Q: How do I make the text fit alongside an image bar? A: It would preferable to control your image placement than try to restrict the size of the fonts, which can be very harmful to the legibility of your documents. One suggestion
is to put the text in a div element with a specific class, and set the bar as a background image.
More details available to subscribers:How do I make the text fit alongside an image bar?
Q: Is it possible to create a frames effect with CSS? A: To create frame-like sites using CSS use a position: fixed declaration on your menu division. You must also set the properties top, left and width. It's best to stick with
percentage values for these lengths, to position your menu according to the size of the users' screen.
More details available to subscribers:Is it possible to create a frames effect with CSS?
Q: Can I scale background images to different screen resolutions? A: It is difficult to answer questions like this without seeing the background image and the visual design you are trying to achieve. If you plan to use a "liquid" page layout,
where the page elements may expand proportionally to the width of the screen, consider how you might slice the image up and use the parts as the background image for
different page elements. In particular, focus on any horizontal lines in the background that may define different navigational parts of the page, these can be the most difficult
part of a liquid design.
More details available to subscribers:Can I scale background images to different screen resolutions?
Q: How can I style browser window components? A: The browser window properties you are seeking to influence are proprietary features of individual browsers that are not currently part of the W3C CSS recommendations.
However, these features are directly accessible in recent versions of Microsoft Internet Explorer and Opera ...
General container questions Q: What's the difference between application servers and Web servers? A: Web servers are primarily designed to deliver Web site content and not much besides. Application servers may include a Web server component, such as a Java servlet
container, but manage it alongside other components, such as an Enterprise JavaBeans container, so that there is a shared execution context amongst them.
Q: How can I write a servlet container using Java? A: You are strongly recommended to join an existing servlet container project rather than write one yourself. A servlet container is an extremely complex system to create
and most implementations have taken many years to develop to a robust, high performance standard. The Apache Tomcat container is an open source project that would be
a good place to start.
Q: Does the servlet run when the container starts up? A: Servlet classes are not normally initialised when the servlet container is first started, they are brought into service when the first request for the servlet is received. Much of
the time this "just in time" approach will not cause a significant delay. If a servlet has overridden the init(ServletConfig) method with a with a lengthy initialisation stage, the
first user must wait for the method to return before the servlet handles their request.
Q: What happens if the server is not loaded into memory? A: If the server or container object is not loaded in memory because it is shutting down or starting up, it will not be listening for requests and cannot accept connections. Any
clients that attempt to connect to the server will normally fail after a client-specific timeout period.
Q: Is the session ID stored in the servlet or container? A: When you first request a session through the HttpServletRequest object, the servlet container manages the creation and storage of a reference to the HttpSession object.
If a subsequent request is received that corresponds with an existing session object, the HttpServletRequest getSession() method will return the session object created in
the first request.
More details available to subscribers:Is the session ID stored in the servlet or container?
Container configuration Q: What is web.xml for? A: The web.xml file contains configuration information for a single Web application. It includes configuration entries for each of the filters and servlets in the application, and a
set of URL mappings for each. There is also a set of configuration entries that apply to every filter, servlet and JSP in the Web application context.
Context, filter and servlet configurations may contain a set of name and value pairs that are loaded by the servlet container when it starts up. The URL mappings tell the
container which resources should be used to process incoming requests, and the configuration parameters are used to pass variables to those resources.
Q: What is a servlet URL mapping? A: A servlet URL mapping is the second part of a servlet configuration in a Web application's web.xml file. The first part declares the servlet and gives it a name, the URL
mapping tells the servlet container on which URL the servlet should operate, as below.
More details available to subscribers:What is a servlet URL mapping?
Q: Do I need a different web.xml for each server? A: The /WEB-INF/web.xml configuration scheme is common to all servlet containers that conform to the Java Servlet Specification version 2.2 and later. Some servlet
containers have supplementary configuration files to apply their own special features. You need a web.xml file for each Web application you create. There is also a web.xml
file for the servlet container as a whole.
Q: How do I load a servlet at start-up? A: To request a servlet is initialized when the container starts up, add the load-on-startup element to the web.xml file in your WEB-INF directory, as below. Any positive
integer value will signal start up initialization.
More details available to subscribers:How do I load a servlet at start-up?
Q: How can I create database connections for all servlets? A: The standard way to preserve database connections between servlet requests is to use a connection pool that governs access to a number of live connections. The pool
uses your primary database driver to create the connections in advance and makes pooled connections available through its own URL identifier. When the application closes
a pooled connection it just returns to the pool.
More details available to subscribers:How can I create database connections for all servlets?
Apache JServ questions Q: I can't compile any servlets and JServ doesn't work! A: If your compiler is failing with missing javax package references, it is very likely your classpath does not include jsdk.jar, the Java Servlet Development Kit. You need to
include a line like this in a backed up copy of your autoexec.bat file and reboot your computer:
Tuesday, November 13, 2007
Thanks,
-jay Message #158594 Post reply Post reply Post reply Go to top Go to top Go to top Hibernate or iBatis Posted by: adrian osullivan on February 25, 2005 in response to Message #158540 I think you've identified the key difference between the two frameworks - HQL vs vendor SQL. At the end of the day, HQL, like JDOQL and EJBQL cannot take full advantage of vendor-specific DB features, such as Oracle pl/sql. The question is, do you frequently use those vendor-specific features? If so, I think Hibernate must be ruled out. If you only use vendor features rarely, Hibernate can be used. In general, it seems more powerful and robust than iBatis, so I would prefer to use it if you can get around the learning curve.
On our project we had a lot of complex procedures which benefitted from a lot of custom PL/SQL so we chose iBatis. Its is also much easier for developers to learn than Hibernate.
However, its worth noting that Hibernate 3 (currently in Beta) will support vendore-specific calls. When that happens, I think iBatis may struggle to compete.
javax.xml.bind.JAXBContext