Monday, January 11, 2010

XML Validation



Validating XML Documents Against XML Schema
By Deepak Vohra
Learn the three methods involved: SAX parser, DOM parser, and XSD validator
XML documents are increasingly being used as a format of data exchange. But for an XML document to be acceptable to different developers/users, the XML document should conform to a standard structure.
XML Schema is an XML-based representation of the structure of an XML document. Through its support for datatypes and namespaces, XML Schema has the potential to provide the standard structure for XML elements and attributes.
However, to check if an XML document conforms to an XML Schema, the document must be validated against that XML Schema. This tutorial explains the procedure for performing that validation using parsers for the Simple API for XML (SAX) and Document Object Model (DOM), as well as an XML Schema Design (XSD) validator. Table 1 compares the different purposes of each of these components. In each case, we will use the Oracle XML Developer's Kit (XDK) 10g Production to perform the validation.

SAXParserDOMParserXSDValidator
used for validating an XML document if parsing is requiredused for validation if the XML document is required to be parsed and a DOM structure of the XML document is to be generatedused for validation of the XML document when parsing is not required

Preliminary Setup
To validate an XML document with the Oracle XDK, parser classes are required in the Java CLASSPATH. First, extract the xdk_nt_10_1_0_1_0A_beta.zip file to an installation directory. Add /lib/xmlparserv2.jar, /lib/xml.jar , and /lib/xschema.jar - to the Java CLASSPATH, where is the directory in which Oracle XDK is installed.
Document to Validate
Before validating an XML document, you must specify the location of the XML Schema.
The location of the XML Schema can be specified with the xsi:schemaLocation attribute for an XML Schema with namespaces, and the xsi:noNamespaceSchemaLocationattribute for an XML Schema without namespaces, in the root/top-level element, or in any other element of the XML Document. In our case, we'll use the example of an XML document, XmlDocumentUrl, that contains an Oracle Magazine catalog.
If the schema location is set in the XML document, the element is defined as



The example XML document is shown in Listing 1.
Validation XML Schema
As I explained previously, an XML Schema—in our example, SchemaUrl—defines the structure of an XML document. The element declarations in an XML Schema can specify the namespace/s of the elements in the XML document. A namespace is defined with the notation xmlns:prefix=prefix is the namespace prefix; the default namespace is specified with xmlns=. The xs:schema element in our example schema document OracleCatalog.xsd is specified with a namespace declaration as



The elements in the OracleCatalog.xsd XML Schema document (see Listing 2) are in the XML Schema namespace of http://www.w3.org/2001/XMLSchema.
Validation of XML Document with SAXParser
Next, we need to validate. First, import the SAXParser class:

import oracle.xml.parser.v2.SAXParser;
Create a SAXParser:
SAXParser saxParser=new SAXParser();
Set the validation mode to report validity errors:
saxParser.setValidationMode(XMLParser.SCHEMA_VALIDATION);
Now set the XML Schema for validation:
XSDBuilder builder = new XSDBuilder();
URL url =  new URL(SchemaUrl);      
XMLSchema schemadoc = (XMLSchema)builder.build(url);
saxParser.setXMLSchema(schemadoc);
Create and register an ErrorHandler with the SAXParser parser. The ErrorHandler class is the Validator class.
Validator handler=new Validator();
saxParser.setErrorHandler(handler);

Parse the XML document to validate with the XML schema.
saxParser.parse(XmlDocumentUrl);
Any errors generated by the parser are registered with the ErrorHandler and may be retrieved from the ErrorHandler.
The example program, XDKValidator.java, used to validate OracleCatalog.xml with OracleCatalog.xsd and the SAXParser API is shown in Listing 3.
Validation with DOMParser
Now, let's validate our XML document with the DOMParser. First, import the DOMParser class:

import oracle.xml.parser.v2.DOMParser;

Create a DOMParser:

DOMParser domParser=new DOMParser();  

Set the validation mode to report validity errors:

domParser.setValidationMode(XMLParser.SCHEMA_VALIDATION);

Set the XML Schema used for validation:

XSDBuilder builder = new XSDBuilder();
URL url =  new URL(SchemaUrl);      
XMLSchema schemadoc = (XMLSchema)builder.build(url);
domParser.setXMLSchema(schemadoc);

Create and register an ErrorHandler with the DOMParser parser. The ErrorHandler class is the Validator class:

Validator handler=new Validator(); 
domParser.setErrorHandler(handler);

Parse the XML document to validate with the XML schema:

domParser.parse(XmlDocumentUrl);

Any errors generated by the parser are registered with the ErrorHandler and may be retrieved from the ErrorHandler. The example program used here, DOMValidator.java, is shown in Listing 4.
Validation with XSDValidator
Import the XSDValidator class:

import oracle.xml.schemavalidator.XSDValidator;

Create an XSDValidator:

XSDValidator xsdValidator=new XSDValidator();

Specify an XML Schema with which to validate the XML document:

XSDBuilder builder = new XSDBuilder();
 URL url =  new URL(schemaUrl);       
 XMLSchema schemadoc = (XMLSchema)builder.build(url);
xsdValidator.setSchema(schemadoc);

Create and register an ErrorHandler with the XSDValidator validator. The ErrorHandler class is the Validator class:




Validator handler=new Validator();
XMLError xmlError=new XMLError();
xmlError.setErrorHandler(handler); 
xsdValidator.setError(xmlError);
Parse the XML document you want to validate with the XML Schema:
xsdValidator.validate(new URL(XMLDocumentUrl));
As before, any errors generated by the parser are registered with the ErrorHandler and may be retrieved there. The example program used here, SchemaValidator.java, is shown in Listing 5. Validate Away You've just learned three different methods for validating an XML doc against XML Schema.  One of them should meet your needs.


XML Elements,Attributes

An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain other elements, simple text or a mixture of both. Elements can also have attributes.

XML elements must follow these naming rules:
  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces
Any name can be used, no words are reserved.

Best Naming Practices

Make names descriptive. Names with an underscore separator are nice: , .
Names should be short and simple, like this: not like this: .
Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.
Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."
Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).
XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.
Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.

XML Elements are Extensible

XML Attributes

XML elements can have attributes in the start tag, just like HTML.
Attributes provide additional information about elements.

XML Attributes Must be Quoted


or like this:

Some of the problems with using attributes are:

  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)                                                                                               The ID above is just an identifier, to identify the different notes. It is not a part of the note itself.What I'm trying to say here is that metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.

Sunday, January 10, 2010

setting CLASSPATH

is an OOP language. In java programming language for compiling the program we use the compiler that converts the source code into the byte code after that, that byte code is interpreted by JVM that converts the bytecode into the machine independent code.  In java how the Java compiler and the JVM use the class search path to locate classes when they are referenced by other Java code. Searching class  path is important for all Java developers.Many  development tools have their own ways of manipulating the class path, which vary from product to product.For doing this we will use only simple command-line tools to carry out the compile operations. No difference, between the way that the Java compiler searches for classes, and the way that the JVM does it at run time. The compiler has the ability to compile classes from source code, where the JVM does not.  We will use the compiler, but similar issues apply at run time.
Searching of multiple class directories
  • javac(compiler)search the files in only one directory at a time.
  • But,  class search path will contain numerous directories and JAR archives. The -classpath option to javac and java allows multiple entries to be specified, but  the syntax is  different for Unix and Windows systems.
For Unix  like this

javac -classpath dir1:dir2:dir3 ...

For Windows like this 
javac -classpath dir1;dir2;dir3 ...

The difference is that Windows uses the colon (:) character as part of a filename, so it can't be used as a filename separator. Naturally the directory separator character is different as well: forward slash (/) for Unix and backslash (\) for Windows.( I ). For running a simple program we need to set the  java path  on command prompt(for temporary )& in Environment variable using PATH variable  & CLASSPATH variable :
PATH variable 
In JDK the PATH variable contains directories where binary files (e.g. EXE files in Windows) will be looked for.We set the PATH variables like this i.e path C:\Java\jdk1.6.0_03\bin 
(i)on command prompt
C:\>set path=%path;C:\Java\jdk1.6.0_03\bin%
When you open a command prompt and type "javac", you're supposed to have the "bin" directory of your sdk into the PATH, otherwise you'll get an infamous "Command not found" error message.
CLASSPATH 
In JDK the CLASSPATH contains directories (or JAR files), from where your java compiler/runtime will look for .class files (and some others). For example, "java Hello.class" will not work unless you set the directory (or JAR file) Hello.class is in, into your CLASSPATH.
i.e.classpath  C:\Java\jdk1.6.0_03\lib

For setting CLASSPATH using command prompt  Java class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
(ii)on command prompt 
C:\>set classpath=%classpath;C:\Java\jdk1.6.0_03\lib%
JARs on the classpath
Java compiler and run-time can search for classes not only in separate files, but also in `JAR' archives. A JAR file can maintain its own directory structure, and Java follows exactly the same rules as for searching in ordinary directories. Specifically, `directory name = package name'. Because a JAR is itself a directory, to include a JAR file in the class search path, the path must reference the JAR itself, not the directory that contains the JAR. This is a very common error. Suppose I have a JAR jarclasses.jar in directory /jarclasses. The Java compiler look for classes in this jar, we need to specify: javac -classpath /jarclasses/jarclasses.jar ...
and not merely the directory jarclasses. For the CLASSPATH  use  CLASSPATH Environment Variable 
In java programming language we use the following packages such as  java.io.*;  java. util.*;These  packages are  just a set of classes, you will want to store them in one place, separate from the directory where you are developing your program. Sometimes these libraries have a set of files stored in a single jar file ( with a .jar extension). From where  the Java compiler and run programs must be able to find any of these. This is done for command line use of Java and for some editors and IDEs by setting an environment variable called CLASSPATH. For  Windows, the CLASSPATH environment variable should look like this :
c:\MyJavaLib;c:\MyJavaLib\myutils.jar;c:\MyJavaLib\blackboxclasses.jar;.
At the end " . "  includes the current directory in the search for classes. 
  • Suppose we have a directory MyJavaLib on the C-drive that contains some utility classes or the directories that correspond to some packages. This  is the part before the first semi-colon.
               
  • Second part indicates that we have some classes stored in a file myutils.jar
             
  • Third part indicates that we have a jar file blackboxclasses.jar. 
Finally, after the last semi-colon we have the period( . ), indicating that the current directory is on the CLASSPATH. If some things are stored in directories that are subdirectories, the complete path, starting with "c:\" should be in the CLASSPATH.
(2)  For  setting CLASSPATH & PATH variable  in environment variable by using the following steps:
(i) right click on my computer icon on desktop
(ii) click on properties
(iii) click on advanced

(iv) click on  Environment variables

(v)  system varables  click on  new

(vi) in ( variable name) write ----- path
in ( variable value)  paste the path till bin directory i.e.------- c:\java\jdk1.6.0_03\bin click on ok

(vii)  in system varables again click on  new

(viii) in ( variable name) write ----- classpath
in ( variable value)  paste the path till lib directory i.e.------- c:\java\jdk1.6.0_03\lib  click on ok

(ix) after finished click on ok

(x) finished click on ok

How to set System Classpath :
Java class path is set for including the various files during program execution & compilation.After setting class search path on the javac command line, we set `system' class path. This  class path  will be used by both the Java compiler and the JVM . In both Unix and Windows systems, this is done by setting an environment variable. For example, in Linux with the bash shell:

CLASSPATH=/jarclasses/jarclasses.jar;export CLASSPATH 

for Windows:

set CLASSPATH=c:\jarclasses\jarclasses.jar

We use this procedure for setting  short-term changes to the system CLASSPATH, but if you want these changes to be persistent you will need to arrange this yourself.For different - 2 system this path  is different . On a Linux system, we  put the commands in the file .bashrc in my home directory. On Windows 2000/NT there is a `Control Panel' page for this.
Setting the system CLASSPATH is a useful procedure if you have JARs full of classes that you use all the time.

Saturday, January 9, 2010

Java 2 SDK 1.4.2 Installation Notes for Microsoft Windows

System Requirements

Software - Java 2 SDK Standard Edition, 1.4.2 is supported on i586 Intel and 100% compatible platforms running Microsoft Windows. For a list of supported operating systems and desktop managers, see System Configurations.

Hardware - Intel and 100% compatible processors are supported. A Pentium 166MHz or faster processor with at least 32 megabytes of physical RAM is required to run graphically based applications. At least 48 megabytes of RAM is recommended for applets running within a browser using the Java Plug-in. Running with less memory may cause disk swapping which has a severe effect on performance. Very large programs may require more RAM for adequate performance.

Installation Instructions

In this procedure, you will run the self-installing executable to unpack and install the Java 2 SDK software bundle. As part of the Java 2 SDK, this installation includes the Java Plug-in and Java Web Start, as well as an option to include the public Java 2 Runtime Environment. (The Java 2 SDK also contains a private J2RE for use only by its tools.)
For issues related to Windows Installation (IFTW) and Java Update, see the Windows Installation (IFTW) and Java Update FAQ. See this note on Proxy Settings and Authentication.

Print or bookmark these instructions - After the Java 2 SDK software has been installed, you may be asked to reboot your system. To continue using these instructions after rebooting, either print this page now, bookmark it now, or use your Web browser's history function to get back to this page.

Troubleshooting - If you have any difficulties, see the Troubleshooting section at the end of this document or submit a bug report for your installation problem.

Note: For any text on this page containing the following notation, you must substitute the appropriate update version number for the notation.
 
For example, if you are downloading the installer for update 1.4.2_01, the following file name:
j2sdk-1_4_2_-windows-i586.exe
would become:
j2sdk-1_4_2_01-windows-i586.exe
1.
 Check the download file size (Optional)
If you save the self-installing executable to disk without running it from the download page at the web site, notice that its byte size is provided on the download page. Once the download has completed, check that you have downloaded the full, uncorrupted software file.
2. If 1.4.2 Beta is installed, uninstall it.
Use the Microsoft Windows Add/Remove Programs utility, accessible from the Control Panel (Start -> Settings -> Control Panel).
3. Run the Java 2 SDK installer
Note - you must have administrative permissions in order to install the Java 2 SDK on Microsoft Windows 2000 and XP. The file j2sdk-1_4_2_-windows-i586-i.exe is the Java 2 SDK installer. If you downloaded it instead of running it directly from the web site, double-click on the installer's icon. Then follow the instructions the installer provides. The installer may ask you to reboot your computer. When done with the installation, you can delete the download file to recover disk space.

Note -- Trying to install the Java 2 SDK on a non-supported version of Microsoft Windows or on a machine that doesn't have a sufficiently up-to-date Service Pack will cause the installer to generate this warning: "We recommend that you do not install this Java Platform for the following reasons: This Java Platform does not support the operating system or operating-system service pack on this machine." See the system requirements above for information on supported configurations of Microsoft Windows.

Installed Directory Tree
The Java 2 SDK has the directory structure shown below.
j2sdk1.4.2_
  ____________________|___________________
 |    |    |    |    |   |     |      |   |
 |    |    |    |   bin lib    |    demo  |
 |    |    | LICENSE |   |     |         jre
 |    | COPYRIGHT              |        __|__
 |  README.txt              include    |     |
readme.html                           bin   lib


In addition, the Java Plug-in and Java Web Start will automatically be installed. Look for a Java Web Start icon on your desktop. There will also be an entry for Java Web Start in the Start -> Programs menu.

Java Web Start --
  • Compatibility: The release of Java Web Start that comes with this SDK/JRE can be run on SDK/JRE 1.2.2 or later. It will not work with SDK/JRE 1.1.x or earlier.
  • Upgrading from Previous Versions: If you have a previous release of Java Web Start, do not uninstall it. Uninstalling it will cause the download cache to be cleared, and all previously installed Java Web Start application data will have to be downloaded again. This new release will overwrite previous installations and automatically update browsers to use this new release. The configuration files and program files folder used by Java Web Start have changed, but all your settings will remain intact after the upgrade, since Java Web Start will translate your settings to the new form.
  • Uninstalling 1.4.2 SDK/JRE: The only way to uninstall Java Web Start 1.4.2 is to uninstall the 1.4.2 SDK/JRE. But note that doing so will remove the 1.4.2 Java Web Start cache, which stores the Java Web Start application data. Uninstalling the SDK/JRE will not, however, remove the cache for previous releases of Java Web Start (1.0.1 and 1.2). Previous releases have separate uninstallers for Java Web Start.
  • Using Java Web Start with Netscape 6.x/7.x: For Netscape 6.x/7.x users, setup the Java Web Start MIME type (JNLP) in the Edit->Preferences->Navigator->Helper Applications section. The file extension is jnlp; MIME Type is application/x-java-jnlp-file. It should be handled by the javaws executable file in your Java Web Start directory. Also note that, due to a problem with the JavaScript in Netscape 6.x/7.x, you must use the non-JavaScript version of the demos page

4. If you want to run Netscape 7.x/Mozilla 1.x with Java Plug-in, do this:
  • Exit the Netscape 7.x/Mozilla 1.x browser and all Netscape 7.x/Mozilla 1.x "objects" (Messenger, Composer ...);
  • If the Quick Launch feature is enabled, disable it;
  • Then restart Netscape 7.x/Mozilla 1.x.
5. Update the PATH variable (Optional)
You can run the Java 2 SDK without setting the PATH variable, or you can optionally set it as a convenience. Should I set the PATH variable?
Set the PATH variable if you want to be able to conveniently run the Java 2 SDK executables (javac.exe, java.exe, javadoc.exe, etc.) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
C:> \j2sdk1.4.2_\bin\javac MyClass.java
It's useful to set the PATH permanently so it will persist after rebooting. How do I set the PATH permanently?
To set the PATH permanently, add the full path of the j2sdk1.4.2_\bin directory to the PATH variable. Typically this full path looks something like C:\j2sdk1.4.2_\bin. Set the PATH as follows, according to whether you are on Microsoft Windows NT or 98/2000/ME.
Microsoft Windows NT, 2000, and XP - To set the PATH permanently:

  1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows 2000 select the Advanced tab and then Environment Variables. Look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to the right end of the "Path" in the User Variables. A typical value for PATH is:

    C:\j2sdk1.4.2_\bin 
    
    Capitalization doesn't matter. Click "Set", "OK" or "Apply". The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should only have one bin directory for a Java SDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to j2sdk1.4.2_\bin.



  2. The new path takes effect in each new Command Prompt window you open after setting the PATH variable.
Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows:
  1. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
  2. Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at the right end:


    PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\J2SDK1.4.2_\BIN 
    
    Capitalization doesn't matter. The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows searches for programs in the PATH directories in order, from left to right. You should only have one bin directory for a Java SDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to j2sdk1.4.2_.


  3. To make the path take effect in the current Command Prompt window, execute the following:

    C:> c:\autoexec.bat
    
    To find out the current value of your PATH, to see if it took effect, at the command prompt, type:

    C:> path
    


Microsoft Windows ME - To set the PATH permanently:
From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select PATH and press the edit button. Now add the SDK to your path as described in step b above. After you've added the location of the SDK to your PATH, save the changes and reboot your machine when prompted.
6. Start using the Java 2 SDK!
Your computer system should now be ready to use the Java 2 SDK. In this step, you'll run some simple commands to make sure it is working properly. If you are new to developing and running programs in the Java programming language, see The Java Tutorial online for some guidance. Note especially the tutorial trails under the heading Trails Covering the Basics.
You can also download the Java 2 SDK documentation from the Java 2 SDK download page..
Uninstalling the Java 2 SDK
If you should ever want to uninstall the Java 2 SDK, use the "Add/Remove Programs" utility in the Microsoft Windows Control Panel. As an alternative method, if you still have the original installation program that you used to install the Java 2 SDK, you can double click on it to launch an uninstall program.



Location of VM Library Files (jvm.dll)

If you use the Invocation API to launch an application directly rather than using the Java application launcher, be sure to use the correct paths to invoke the Java HotSpot Client Virtual Machine (VM) or Java HotSpot Server VM, as desired. The path within the Java SDK to the Java HotSpot Client VM is:
jre/bin/client/jvm.dll (on x86)
The path to the Java HotSpot Server VM is:
jre/bin/server/jvm.dll (on x86)
jre/bin/server/jvm.dll (on IA64)
The corresponding locations in the Java 2 Runtime Environment begin with j2re1.4.2 instead of jre. The Exact VM and Classic VM are no longer part of the Java 2 SDK, and existing code that uses the Invocation API to launch an application based on old paths to the Exact or Classic VMs will not work.

Troubleshooting the Installation

Below are some tips for working around problems that are sometimes seen during or following an installation. For more troubleshooting information, see the Java FAQ.

  • If Netscape 6.2.x fails to launch a 1.4.2 applet and you installed 1.4.2 after you installed 1.4 (and both are still installed), do either of the following:


    • Uninstall 1.4 before you install 1.4.2;
    • Before you install 1.4.2, open the 1.4 Java Plug-in Control Panel, select the Browser tab, and deselect Netscape 6.



  • If you see the following error message about Microsoft Windows Installer 2.0:

    An error occured while downloading the file
    http://www.installengine.com/Msiengine20/instmsiw.exe.
    What would you like to do?
    
    When installing version 1.4.2 of Java 2 Runtime Environment or Java 2 SDK (using the default minimized download rather than the single executable), InstallShield requires Microsoft Windows Installer 2.0 to be on your machine; if it is not found (or an older version is found), then InstallShield automatically tries to download Microsoft Windows Installer 2.0. If your machine is not on the Internet or is behind an authenticated proxy, the installation will fail at that point. To proceed, simply use the Windows Offline Installer from the download page. Microsoft Windows Installer 2.0 is included in this download.
    Alternatively, you can manually download Microsoft Windows Installer 2.0 by going to microsoft.com and searching for "Windows Installer 2.0".
    Version 2.0 of Microsoft Windows Installer is included in Windows XP and Windows 2000 Service Pack 3, but not in earlier versions of Windows.
    To see which version of Microsoft Windows Installer is installed, do the following:



    1. Locate the file MSI.DLL. (Usually located in C:\WINNT\SYSTEM32 )
    2. Select the file and right-click on it.
    3. Choose "Properties" and click on the "Version" tab.



  • If you get an error about one of the following during InstallShield setup:


    • Error extracting support files. A typical error message is An Installation support file could not be installed. The filename, directory or volume label syntax is incorrect.
    • Error installing Ikernel.exe (0x any number)
    • Access is denied
    • Error loading Type Library/DLL
    These errors could be caused by a known problem with InstallShield. See the InstallShield web site for a discussion of this problem with possible solutions: http://support.installshield.com/kb/view.asp?pcode=ALL&articleid=Q104985


  • If you see the following error message:

    The InstallShield engine (iKernel.exe) could not be launched.
    Error loading type library/DLL
    
    This message probably indicates that system file Stdole32.tlb is missing from your computer. You can obtain this file from the Microsoft web site. For Microsoft Windows 98 platforms, for example, this file is included in the DCOM98 product.


  • If you see the following error message on Microsoft Windows 2000

    config.nt. The system file is not suitable for running MS-DOS 
    and Microsoft Windows Applications.
    
    it indicates a problem with the %SystemRoot%\System32\COMMAND.COM file that has been seen on some installations of Microsoft Windows 2000. If you encounter this error message when you try to launch the installer, consult the Microsoft web site at:

    http://support.microsoft.com/support/kb/articles/Q142/2/71.asp
    
    for information about resolving the problem.


  • If you see the following error message

    corrupt cabinet file
    
    then the file you have downloaded is corrupted. (A cabinet file contains compressed application, data, resource and DLL files.) Check its file size against the expected file size listed in these instructions. If they don't match, try downloading the bundle again.


  • If you see the following error message

    System Error during Decompression
    
    then you might not have enough space on the disk that contains your TEMP directory.


  • If you see the following error message

    This program cannot be run in DOS mode.
    
    then do the following:


    1. Open the MS-DOS shell or Command Prompt window
    2. Right-click on the title bar
    3. Select Properties
    4. Choose the Program tab
    5. Push the Advanced button
    6. Make sure the item "Prevent MS-DOS-based programs from detecting Windows" is unchecked
    7. Select OK
    8. Select OK again
    9. Exit the MS-DOS shell
    10. Restart your computer.



  • Private vs. public J2RE - Installing the Java 2 SDK installs a private Java 2 Runtime Environment and optionally a public copy. The private J2RE is required to run the tools included with the Java 2 SDK. It has no registry settings and is contained entirely in a jre directory (typically at C:\Program Files\j2sdk1.4.2\jre) whose location is known only to the SDK. On the other hand, the public J2RE can be used by other Java applications, is contained outside the SDK (typically at C:\Program Files\Java\j2re1.4.2), is registered with the Windows registry (at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft), can be removed using Add/Remove Programs, might or might not be registered with browsers, and might or might not have java.exe copied to the Windows system directory (making it the default system Java platform or not).
  • Creating source files in Notepad - In Microsoft Windows, when you create a new file in Microsoft Notepad and then save it for the first time, Notepad normally adds the .txt extension to the filename. Therefore, a file you name Test.java is saved as Test.java.txt. It's important to note that you cannot see the .txt extension unless you turn on the viewing of file extensions (in Microsoft Windows Explorer, uncheck "Hide file extensions for known file types" under Folder Options). To prevent the .txt extension, enclose the filename in quotation marks, such as "Test.java", when typing it into the Save As dialog box. On the other hand, Microsoft WordPad does not add a file extension if you provide one -- you must save the file as "Text Document".

  • Choosing an installation path containing characters that are not part of the system code page - On Windows 2000, XP, and 2003, it is possible to name directories using characters that are not part of the system locale's code page. If such a directory is part of the installation path, then error 1722 occurs, and installation is not completed. To prevent this problem, make sure that the user and system locales are identical, and that the installation path only contains characters that are part of the system locale's code page. User and system locales can be set in the Regional Options or Regional Settings control panel.
    The associated bug number is 4895647.

ABCD

Object Serialization

Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file-system, or more generally, to a transmission medium or storage facility.
          To do I/O on a text file for the purpose of storing and loading data. The parsing these files always seems to reduce to a basic set of hurdles that you must get over: Did I reach the EOF marker? Is the file pointer on top of the integer or the string? What happens when I reach the EOLN mark, and what if the marker is missing? Now consider a situation where a programming language suddenly made these problems go away? Object serialization has taken a step in the direction of being able to store objects instead of reading and writing their state in some foreign and possibly unfriendly format.
        Serializing an object requires only that it meets one of two criteria. The class must either implement the Serializable interface (java.io.Serializable) which has no methods that you need to write or the class must implement the Externalizable interface which defines two methods. As long as you do not have any special requirements, making a serializable is as simple as adding the ``implements Serializable'' clause.
         An important modifier that your can use for object data is the transient  keyword. If a field in a class is marked as transient, it will automatically be skipped when serializing any objects that are instances of that class. This is very useful for references that are ``relative to an address space'' they were created in, such as stream objects, file references and network connections. This is a key attribute of a class that should be considered when attaching the Serialization or Externalizable interface to a class you are writing.
         One thing to remember about de-serializing an object is that the class must have a public constructor that takes no arguments. This is to allow the serialization mechanism to create an empty object and then fill in the data.
          The serialization mechanism uses an identification value to keep track of all classes. This identifier, called the serialVersionUID (SUID), is computed from the structure of the class file to form a unique 64-bit identifier. It is possible to explicitly indicate which serialVersionUID your class is compatible with. In plain English, you can tell the serialization mechanism which version of your class you are compatible with.


static final long serialVersionUID = 7110175216435025451L;
If you include this in the class data, the serialization mechanism will understand which past version of the class you intend to be compatible with the current implementation.



Applications

There are already numerous projects in progress that will take advantage of the serialization process, two of which have resulted in Java 1.1 features. One is remote method invocation (RMI)  where objects seem to be transparently transported over the network and reconstituted for use on a machine other than the one it originally was created on. RMI is the rough equivalent of the remote procedure call(RPC) , done ``object-oriented'' style. In effect, with minimal code overhead, you can invoke methods on objects which exist on a machine which your program has access to via a network. Object serialization plays a key role in being able to pass arguments and return values over the network in a seemingly transparent manner.
A second application of serialization appears in the implementation of JavaBeans. The designers wanted it to be easy and intuitive to have Beans save their state and then be recalled with that state at a later date. For this reason, all Beans must be serializable, implementing either the Serializable or Externalizable interface.

Conclusion

Object serialization is not a technology that will impress an audience during a presentation, nor will it boost product sales all by itself. Serialization is a building block that will allow the creation of potentially earth-shaking technologies for Java. We have seen some of these technologies, like JavaBeans and RMI, surface already
Example:

import java.io.*;

  public class SerializingObject{
  
  
public static void main(String[] argsthrows IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter File name : ");
  
    
String file = in.readLine();

   
System.out.print("Enter extention : ");
  
    
String ext = in.readLine();
 
  
String filename = file + "." + ext;

   
File f = new File(filename);
 
  
try{
  
   
ObjectOutput ObjOut = new ObjectOutputStream(new FileOutputStream(f));

     
ObjOut.writeObject(f);
 
    
 ObjOut.close();

     
System.out.println("Serializing an Object Creation completed successfully.");
  
    
}
   
catch(IOException e){
  
   
System.out.println(e.getMessage());

      }
  
}


  }


Output of the Program:

C:\nisha>javac SerializingObject.java

C:\nisha>java SerializingObject
Please enter File name : Filterfile
Enter extention : txt
Serializing an Object Creation is completly Successfully.

C:\nisha>



XML

XML can store data, but it is not a database. XML can serialize objects, but an XML document is not an object. Web pages can be written in XML, but XML is not HTML. Functional (and other) programming languages can be written in XML, but XML is not a programming language. Books are written in XML, but that doesn't make XML desktop publishing software.


XML Makes Your Data More Available

Since XML is independent of hardware, software and application, XML can make your data more available and useful.
Different applications can access your data, not only in HTML pages, but also from XML data sources.
With XML, your data can be available to all kinds of "reading machines" (Handheld computers, voice machines, news feeds, etc), and make it more available for blind people, or people with other disabilities.

XML is Used to Create New Internet Languages

A lot of new Internet languages are created with XML.
Here are some examples:
  • XHTML the latest version of HTML 
  • WSDL for describing available web services
  • WAP and WML as markup languages for handheld devices
  • RSS languages for news feeds
  • RDF and OWL for describing resources and ontology
  • SMIL for describing multimedia for the web  

    An Example XML Document

    XML documents use a self-describing and simple syntax:

    <note>
        <to>Toveto>
        <from>Janifrom>
        <heading>Reminderheading>
        <body>Don't forget me this weekend!body>
    note>
    The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1 = Latin-1/West European character set).
    The next line describes the root element of the document (like saying: "this document is a note"):
    The next 4 lines describe 4 child elements of the root (to, from, heading, and body):
    Tove
    Jani
    Reminder
    Don't forget me this weekend!
    And finally the last line defines the end of the root element:


    All elements can have sub elements (child elements):

     
        .....
     



    Example:

    DOM node tree The image above represents one book in the XML below:

     
       
        Giada De Laurentiis
        2005
        30.00
     

     
       
        J K. Rowling
        2005
        29.99
     

     
       
        Erik T. Ray
        2003
        39.95
     



    All elements must have a closing tag:
    This is a paragraph

    This is another paragraph


    XML Tags are Case Sensitive

    XML Elements Must be Properly Nested

    This text is bold and italic

    XML Documents Must Have a Root Element

    XML documents must contain one element that is the parent of all other elements. This element is called the root element.

     
        .....
     


    XML Attribute Values Must be Quoted

    This will generate an XML error:
    if salary < 1000 then
    To avoid this error, replace the "<" character with an entity reference:
    if salary < 1000 then
    There are 5 predefined entity references in XML:
    < < less than
    > > greater than
    & & ampersand 
    ' ' apostrophe
    " " quotation mark
    Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.





    White-space is Preserved in XML

    HTML truncates multiple white-space characters to one single white-space:
    HTML: Hello           my name is Tove
    Output: Hello my name is Tove.
    With XML, the white-space in a document is not truncated.

    XML Stores New Line as LF


Interface Iterator

public interface Iterator
An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:
  • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
  • Method names have been improved.
This interface is a member of the Java Collections Framework.
Methods:


        1.hasNext

  • public boolean hasNext()
  • Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
    2.next
public Object next()
Returns the next element in the iteration.
Returns:
the next element in the iteration.
Throws:
NoSuchElementException - iteration has no more elements
3.remove
public void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method
Example:









  1. /*
      Iterate through a Collection using Java Iterator Example
  2.   This Java Example shows how to iterate through a Collection using Java Iterator.
  3. */
  4. import java.util.Iterator;
  5. import java.util.ArrayList;
  6. public class JavaIteratorExample {
  7. public static void main(String[] args) {
  8. //create an ArrayList object
  9. ArrayList aList = new ArrayList();
  10. //populate ArrayList object
  11. aList.add("1");
  12. aList.add("2");
  13. aList.add("3");
  14. aList.add("4");
  15. aList.add("5");
  16. /*
  17.       Get Iterator object by invoking iterator method of collection.
  18.       Iterator provides hasNext() method which returns true if has more
  19.       elements. next() method returns the element in iteration.
  20.  */
  21. Iterator itr = aList.iterator();
  22. //iterate through the ArrayList values using Iterator's hasNext and next methods
  23. while(itr.hasNext())
  24. System.out.println(itr.next());
  25. /*
  26.   Please note that next method may throw a java.util.NoSuchElementException
  27.       if iteration has no more elements.
  28.  */
  29. }
  30. }
  31. /*
  32. Output would be
  33. 1
  34. 2
  35. 3
  36. 4
  37. 5
  38. */