Friday, November 27, 2009

Causes of java.lang.ClassNotFoundException


Class loading issues are a common frustration for many Java developers. The dreaded java.langClassNotFoundException means they can forget about going home at a reasonable hour. While Java class loading is very powerful feature, it is also a very flexible and confusing feature. But don’t let this exception scare you. The majority of the time, there are three very practical things to look at in order to resolve the issue.
  1. If you are loading a class by name either using Class.forName() or an Inversion of Control container like Spring it may be as simple as the class name was spelled incorrectly. Validate the fully qualified class name is spelled correctly. The best way is to use the Eclipse “Copy Qualified Name” feature or copying and pasting the package name and class name directly from the source file.
  2. The mostly likely culprit is the class can not really be found. This can be caused by the directory or jar file containing class not being included in the JVM classpath. The other common cause when multiple class loaders are involved such as in a web container or application server is a visibility problem. For example classes in an ejb-jar do not have access to classes in the war file for the majority of application servers. But classes in the war file have access to classes in the ejb-jar. The reason is the war file typically has its own class loader which is a child class loader of the ear class loader. The basic rule is children class loaders have access to their parents but not visa versa. For this error, check your application server’s class loading documentation and make sure the class that is trying to access the not found class has the acceptable access.
  3. The most challenging cause to debug is a dependency issue during initialization of a class. During initialization if a class can’t find certain resources it depends on such as other classes or files, this may result in a ClassNotFoundException. To resolve this, you may need to validate all dependencies are available. If you have the code, you can look at the class imports and any static initilization. If you don’t, you might need to reverse engineer the class to determine the dependencies.
I hope this helps. Just remember the cause of ClassNotFoundExceptions can be difficult to resolve but they are always deterministic so stick with it.


Friday, November 20, 2009

What is cloud computing?


Before cloud computing
Traditional business applications—like those from SAP, Microsoft, and Oracle—have always been too complicated and expensive. They need a data center with office space, power, cooling, bandwidth, networks, servers, and storage. A complicated software stack. And a team of experts to install, configure, and run them. They need development, testing, staging, production, and failover environments.
When you multiply these headaches across dozens or hundreds of apps, it’s easy to see why the biggest companies with the best IT departments aren’t getting the apps they need. Small businesses don’t stand a chance.
Cloud-computing: a better way
Cloud computing is a better way to run your business. Instead of running your apps yourself, they run on a shared data center. When you use any app that runs in the cloud, you just log in, customize it, and start using it. That’s the power of cloud computing.
Businesses are running all kinds of apps in the cloud these days, like CRM, HR, accounting, and custom-built apps. Cloud-based apps can be up and running in a few days, which is unheard of with traditional business software. They cost less, because you don’t need to pay for all the people, products, and facilities to run them. And, it turns out they’re more scalable, more secure, and more reliable than most apps. Plus, upgrades are taken care of for you, so your apps get security and performance enhancements and new features—automatically.
The way you pay for cloud-based apps is also different. Forget about buying servers and software. When your apps run in the cloud, you don’t buy anything. It’s all rolled up into a predictable monthly subscription, so you only pay for what you actually use.
Finally, cloud apps don’t eat up your valuable IT resources, so your CFO will love it. This lets you focus on deploying more apps, new projects, and innovation.
The bottom line: Cloud computing is a simple idea, but it can have a huge impact on your business.



Wednesday, November 18, 2009

Overview of XML


XML (Extensible Markup Language) is a popular and widely-implemented standard: you can use XML to create documents and data records that are fully portable and platform-independent.
This tutorial provides a brief overview of XML to help you become familiar with the markup language's most common features. After reading the tutorial, you should be able to read examples that use XML syntax and understand the basic structure of an XML document. The tutorial concentrates on the technical rather than the business side of XML, and is aimed at technical specialists such as software engineers and documentation writers who are approaching XML for the first time.


Although XML 1.0 is not a complicated format, there are many more details (and much terminology) that this tutorial does not cover. If you are planning to implement software that reads or writes XML directly (rather than through a specialized library), then you will need to refer to the XML 1.0 Recommendation, which is available online and free of charge from the World Wide Web Consortium: the Recommendation is the single authoritative source for all XML work.

1. Markup and Text

Here's a complete (but very simple) XML document:
<?xml version="1.0"?>
<contact-info>
<name>Jane Smith</name>
<company>AT&amp;T</company>
<phone>(212) 555-4567</phone>
</contact-info>
There are two different kinds of information in this example:
1.     markup, like “<contact-info>” and “&amp;”; and
2.     text (also known as character data), like “Jane Smith” and “(212) 555-4567”.
XML documents mix markup and text together into a single file: the markup describes the structure of the document, while the text is the document's content. Here's the same XML document again, with the markup highlighted to distinguish it from the text:
<?xml version="1.0"?>
<contact-info>
<name>Jane Smith</name>
<company>AT&amp;T</company>
<phone>(212) 555-4567</phone>
</contact-info>
The rest of this tutorial shows you how to use different kinds of markup and text in an XML document:
·         the XML declaration;
·         tags and element;
·         attributes;
·         references; and
·         text.

2. The XML Declaration

All XML documents can optionally begin with an XML declaration. The XML declaration provides at a minimum the number of the version of XML in use:
<?xml version="1.0"?>
Currently, 1.0 is the only approved version of XML, but others may appear in the future.
The XML declaration can also specify the character encoding used in the document:
<?xml version="1.0" encoding="UTF-8"?>
All XML parsers are required to support the Unicode “UTF-8” and “UTF-16” encodings; many XML parser support other encodings, such as “ISO-8859-1”, as well.
There a few other important rules to keep in mind about the XML declaration:
1.     the XML declaration is case sensitive: it may not begin with “<?XML” or any other variant;
2.     if the XML declaration appears at all, it must be the very first thing in the XML document: not even whitespace or comments may appear before it; and
3.     it is legal for a transfer protocol like HTTP to override the encoding value that you put in the XML declaration, so you cannot guarantee that the document will actually use the encoding provided in the XML declaration.

3. Tags and elements

XML tags begin with the less-than character (“<”) and end with the greater-than character (“>”). You use tags to mark the start and end of elements, which are the logical units of information in an XML document.
An element consists of a start tag, possibly followed by text and other complete elements, followed by an end tag. The following example highlights the tags to distinguish them from the text:
<p><person>Tony Blair</person> is <function>Prime 
Minister</function> of <location><country>Great
Britain</country></location></p>.
Note that the end tags include a solidus (“/”) before the element's name. There are five elements in this example:
1.     the p element, that contains the entire example (the person element, the text “ is ”, the function element, the text “ of ”, and the location element);
2.     the person element, that contains the text “Tony Blair”;
3.     the function element, that contains the text “Prime Minister”;
4.     the location element, that contains the country element; and
5.     the country element, that contains the text “Great Britain”.
There are a few rules to keep in mind about XML elements:
1.     Elements may not overlap: an end tag must always have the same name as the most recent unmatched start tag. The following example is not well-formed XML, because “</person>” appears when the most recent unmatched start tag was “<function>”:
2.           <!-- WRONG! -->
3.           <function><person>President</function> Xyz</person>
The following example shows the tags properly nested:
<person><function>President</function> Xyz</person>
4.     An XML document has exactly one root element. As a result, the following example is not a well-formed XML document, because both the a and b elements occur at the top level:
5.           <!-- WRONG! -->
6.           <a>...</a>
7.           <b>...</b>
The following example fixes the problem by including both the a and b elements within a new x root element:
<x>
<a>...</a>
<b>...</b>
</x>
8.     XML element (and attribute) names are case-sensitive, so “location” and “Location” refer to different elements. This is a very nasty trap for people used to working with HTML or other SGML document types, because it can cause surprising bugs in processing software, or can even lead to malformed XML documents, as in the following example:
9.           <!-- WRONG! -->
10.       <a href="pbear.html">polar bear</A>
This example will cause a parser error because an XML processor considers a and A to be separate elements, so the start and end tags do not match.
In some cases, an element may exist that has no content (for example, the HTML hr element), but the tag is still read by processors. Rather than type a start and end tag with nothing between them (for example, “<hr></hr>”), XML has a specialempty-element tag that represents both the start tag and the end tag:
<p>Stuff<hr/>
More stuff.</p>
In this example, “<hr/>” represents both the start and the end of the hr element; it could just as easily have been written as “<hr></hr>” (which is exactly equivalent).

4. Attributes

In addition to marking the beginning of an element, XML start tags also provide a place to specify attributes. An attribute specifies a single property for an element, using a name/value pair. One very well known example of an attribute is href in HTML:
<a href="http://www.yahoo.com/">Yahoo!</a>
In this example, the content of the a element is the text “Yahoo!”; the attribute href provides extra information about the element (in this case, the Web page to load when a user selects the link).
Every attribute assignment consists of two parts: the attribute name (for example, href), and the attribute value (for example,http://www.yahoo.com/). There are a few rules to remember about XML attributes:
1.     Attribute names in XML (unlike HTML) are case sensitive: HREF and href refer to two different XML attributes.
2.     You may not provide two values for the same attribute in the same start tag. The following example is not well-formed because the b attribute is specified twice:
3.           <a b="x" c="y" b="z">....</a>
4.     Attribute names should never appear in quotation marks, but attribute values must always appear in quotation marks in XML (unlike HTML) using the " or ' characters. The following example is not well-formed because there are no delimiters around the value of the b attribute:
5.           <!-- WRONG! --> 
6.           <a b=x>...</a>
You can use the pre-defined entities “&quot;” and “&apos;” when you need to include quotation marks within an attribute value (see References for details).
Some attributes have special constraints on their allowed values: for more information, refer to the documentation provided with your document type.

5. References

A reference allows you to include additional text or markup in an XML document. References always begin with the character “&” (which is specially reserved) and end with the character “;”.
XML has two kinds of references:
entity references
An entity reference, like “&amp;”, contains a name (in this case, “amp”) between the start and end delimiters. The name refers to a predefined string of text and/or markup, like a macro in the C or C++ programming languages.
character references
A character references, like “&#38;”, contains a hash mark (“#”) followed by a number. The number always refers to the Unicode code for a single character, such as 65 for the letter “A” or 233 for the letter “�”, or 8211 for an en-dash.
For advanced uses, XML provides a mechanism for declaring your own entities, but that is outside the scope of this tutorial. XML also provides five pre-declared entities that you can use to escape special characters in an XML document:
Character
Predeclared Entity
&
&amp;
< 
&lt;
> 
&gt;
"
&quot;
'
&apos;
For example, the corporate name “AT&T” should appear in the XML markup as “AT&amp;T”: the XML parser will take care of changing “&amp;” back to “&” automatically when the document is processed.

6. Text

If you are working with 8-bit characters, you can usually type printing characters from the 7-bit (non-accented) US-ASCII character set directly into an XML document, except for the special characters “<” and “&”, and sometimes, “>” (it's best to escape it as well just to be safe). Whenever you need to include one of these three characters in the text of an XML document, simply escape it using an entity reference as described in the References section:
<formula>x &lt; (x + 1)</formula>
For “<”, use “&lt;”, for “&”, use “&amp;”, and for “>”, use “&gt;”.
Above character position 127, things become a little trickier on some systems, because by default XML uses UTF-8 for 8-bit character encoding rather than ISO-8859-1 (Latin Alphabet # 1), which HTML and many computer operating systems use by default. UTF-8 and ISO-8859-1 are both essentially identical with US-ASCII up to position 127; for higher characters (those with accents), UTF-8 uses multi-byte escape sequences.
That means that in a UTF-8 XML document, you cannot simply use a single byte with decimal value 233 to represent “�” (and there is no predefined &eacute; entity as there is in HTML); instead, you must either enter the UTF-8 multi-byte escape sequence, or use a special kind of XML reference called a character reference:
<p>That is everyone's favourite caf&#233;.</p>
When your text consists primarily of unaccented Roman characters, this is often the easiest way to escape the occasional accented or non-Roman character. Since “�” appears at position 233 in Unicode (as in ISO-8859-1), the XML parser will read the string correctly as “That is everyone's favourite caf�.”