What is a Web Services
There is no one agreed definition of the term "Web Services," as it is defined somewhat differently by the various software vendors who are providing this technology or using it in some form. The official definition of the term, as specified by the W3C, the World Wide Web Consortium—a global organization that designs, develops, promotes, and encourages standardization of Web-related technologies—is as follows:
"A Web service is a software system identified by a URI, whose public interfaces and bindings are defined and described using XML. Its definition can be discovered by other software systems. These systems may then interact with the Web service in a manner prescribed by its definition, using XML based messages conveyed by Internet protocols."
This is a fairly technical definition, so let's dissect it a little to understand what it means. To start with, let's look at some of the terminology that is used. (A good resource for all Web-related terminology can be found at Webopedia).
URI (Uniform Resource Identifier) is the generic term for all types of names and addresses that refer to objects on the Web. A URI designates a specific resource on the Internet and also designates a method to access the resource. The familiar URL (Uniform Resource Locator) we use to reference a particular web page is one kind of URI.
XML (extensible markup language) is a specification similar to HTML, but which goes beyond simple document presentation to capturing data in a meaningful and structured format so that it can be exchanged between applications that need that data. XML uses user-defined tags to describe data types, and also includes mechanisms to address and associate sets of data, referred to as resources. The XML specification comes from the same source, W3C, described earlier.
The Internet protocol in the Web Services definition refers primarily to SOAP (which was formerly an acronym for "Simple Object Access Protocol," but is now seen as just a name after growing into something that is no longer simple or object-access specific). SOAP is a lightweight XML-based messaging protocol, independent of any operating system, which encodes XML data as well as request and response messages before sending them over a network. Thus, while XML is used to tag the data to make it semantically meaningful, the actual process of transferring that data across a network is done using SOAP. In essence, SOAP is the glue that binds Web Services together. Other core protocols include WSDL, a specification for describing a Web Service (the service methods, message types, etc.), and UDDI, a mechanism to publish and discover Web Services.
Putting it all together and in less technical terms, Web Services is a technology that integrates different Web-based applications from different sources by allowing them to directly communicate data, semantics, and processes with each other, independent of any specific operating system or programming language, and automatically, without human intervention. The future trend in computing appears to be a move away from traditional desktop and client-server based applications towards applications that are fully developed and deployed over the Internet, that can also communicate with other Web-based applications dynamically in real-time to provide more integrated solutions to specific user tasks. Web Services is a crucial enabling technology for such applications, so we are likely to keep hearing a lot more about it in technology circles. Many of the leading high-tech companies are offering development platforms and environments that support Web Services, including Microsoft with .NET, IBM with Web Sphere, BEA Systems with Web Logic, and Sun Microsystems with the Sun Java Enterprise System. (Note that the IBM, BEA, and Sun products are all based on the Java platform.)
Web services with Net Beans 5.5
TIBCO
IBCO Software Inc. is a global company that develops integration software for companies including those in the energy, manufacturing, retail, healthcare, and financial services industries. Its headquarters is in Palo Alto, California, with offices in North America, Europe, Asia, the Middle East, Africa and South America. The company's major commercial competitors are IBM Oracle Corporation, and SAP AG.
In addition, TIBCO offers the message-oriented middleware products Rendezvous and Smart Sockets (from Talarian acquisition). In 2009, TIBCO enters the grid computing and cloud computing markets by acquiring Data Synapse.
TIBCO is an indirect successor to Teknekron Software Systems, Inc. Teknekron was formed in 1983 and produced a software product it called The Information Bus (TIB), which included as a substantial application the processing of stock quotes. In 1994, Teknekron was acquired by Reuters, but was spun out as a separate company in 1994, named Tibco, after the TIB product. In January 1997 Tibco Software Inc. was established as a separate entity to create and market software for integration of business applications outside the financial services sector. Reuters retained Tibco Finance to create and market software solutions for the financial services sector. In July 1999, Tibco went public on the Nasdaq Stock Market under the ticker symbol TIBX.
Greg the Architect
Starting in 2007, Tibco promoted video and print ads starring an action figure called "Greg the Architect. Since launching, the videos have been mentioned in numerous industry blogs, including the Wall Street Journal.
The campaign won an IAC Award (Internet Advertising Competition) in March 2007. They were then honored with the B to B Best Award for Best Online Campaign from B to B Magazine. "Greg" also won a Stevie Award for Best Corporate Film or Video in the Public Relations category at the 2007 American Business Awards.
Greg the Architect has been used in print as a comic strip in many industry magazines covering SOA and BPM. The campaign was also written about in a book from Harvard Business Press entitled Groundswell concerning marketing using social technology. In a blog written by the authors of Groundswell, Greg parodies himself.
By - Ramesh
Please find more topics under JASe Archive!!!
Thursday, October 1, 2009
WHAT'S NEW IN JAVA
JAVAFX
What is JavaFx
JavaFX is a software platform for creating and delivering rich Internet applications that can run across wide variety of connected devices. The current release (JavaFX 1.2, June 2009) enables building applications for desktop, browser and mobile phones. TV set-top boxes, gaming consoles, Blu-ray players and other platforms are planned
Over View
JavaFX is an expressive client platform for creating and delivering rich Internet experiences across all screens of your life. It combines the best capabilities of the Java platform with comprehensive, immersive media functionality into an intuitive and comprehensive, one-stop development environment.
Features
* Provides a unified development and deployment model for building rich client applications
* Enables you to easily integrate audio and video, graphics, rich text, and Web services
* Allows creative developers to program in a visual context
* Provides tools to build and deliver rich Internet applications for desktop, mobile, TV, and other consumer platforms
* Enables unprecedented collaboration between designers and developers
* Allows designers and Java developers to easily leverage the best of today's advanced enterprise software and rich Internet applications
Technology
JavaFX provides a productive development environment for web developers, mashup authors, and Java developers to quickly and easily build the next generation of rich internet applications (RIAs). With JavaFX, designers and developers can collaborate on building high-impact RIAs. Designers gain a broad set of tools to complete the designer/developer workflow, and developers have a simple, declarative scripting language with the right set of tools.
Latest Version
Java fx1.2 SDK
Current Release
1. The Java FX SDK: Java FX compiler and runtime tools. Graphics, media web services, and rich text libraries
2. Net Beans IDE for JavaFX: Net Beans with drag-and-drop palette to add objects with transformations, effects and animations plus set of samples and best practices. For Eclipse users there is a community-supported plugin hosted on Project Kenai
3. Tools and plug-in for creative tools (a.k.a. Production Suite): Plugins for Adobe Photoshop and Adobe Illustrator that can export graphics assets to JavaFX Script code, tools to convert SVG graphics into JavaFX Script code and preview assets converted to JavaFX from other tools.
Technical highlights
Common profile. JavaFX is based on the concept of a Common profile that is intended to span across all devices supported by JavaFX. This approach makes it possible for developers to use a common programming model while building an application targeted for both desktop and mobile devices and to share much of the code, graphics assets and content between desktop and mobile versions. To address the need for tuning applications for the needs of specific class of devices, the JavaFX 1.1 platform includes APIs that are desktop or mobile-specific. For example JavaFX Desktop profile includes Swing and advanced visual effects.
Drag-to-Install. From the point of view of the end user Drag-to-Install allows them to drag a JavaFX widget or application residing in a website within the browser window and drop it onto their desktop. The application will not lose its state or context even after the browser is closed. An application can also be re-launched by clicking on a shortcut that gets automatically created on the user's desktop. This behavior is enabled out-of-the-box by the Java applet mechanism and is leveraged by JavaFX from the underlying Java layer. Sun touts Drag-to-Install as opening up of a new distribution model and allowing developers to break away from the browser.
Integrating graphics created with third-party tools. JavaFX includes a set of plug-ins for Adobe Photoshop and Illustrator that enable advanced graphics to be integrated directly into JavaFX applications. The plug-ins generate JavaFX Script code that preserves layers and structure of the graphics. Developers can then easily add animation or effects to the static graphics imported. There is also an SVG graphics converter tool (a.k.a. Media Factory) that allows for importing graphics and previewing assets after the conversion to JavaFX format.
JavaFX 1.1
JavaFX for mobile development was finally made available as part of the JavaFX 1.1 release announced officially on February 12 2009.
JavaFX 1.2
JavaFX 1.2 was released at JavaOne on June 2, 2009. This release introduced [3]:
* Full support for Linux and Solaris,
* Built-in controls and layouts,
* Skinnable CSS controls,
* Built-in chart widgets,
* JavaFX I/O management, masking differences between desktop and mobile devices,
* Speed improvements.
By - Ravi
Please find more topics under JASe Archive!!!
What is JavaFx
JavaFX is a software platform for creating and delivering rich Internet applications that can run across wide variety of connected devices. The current release (JavaFX 1.2, June 2009) enables building applications for desktop, browser and mobile phones. TV set-top boxes, gaming consoles, Blu-ray players and other platforms are planned
Over View
JavaFX is an expressive client platform for creating and delivering rich Internet experiences across all screens of your life. It combines the best capabilities of the Java platform with comprehensive, immersive media functionality into an intuitive and comprehensive, one-stop development environment.
Features
* Provides a unified development and deployment model for building rich client applications
* Enables you to easily integrate audio and video, graphics, rich text, and Web services
* Allows creative developers to program in a visual context
* Provides tools to build and deliver rich Internet applications for desktop, mobile, TV, and other consumer platforms
* Enables unprecedented collaboration between designers and developers
* Allows designers and Java developers to easily leverage the best of today's advanced enterprise software and rich Internet applications
Technology
JavaFX provides a productive development environment for web developers, mashup authors, and Java developers to quickly and easily build the next generation of rich internet applications (RIAs). With JavaFX, designers and developers can collaborate on building high-impact RIAs. Designers gain a broad set of tools to complete the designer/developer workflow, and developers have a simple, declarative scripting language with the right set of tools.
Latest Version
Java fx1.2 SDK
Current Release
1. The Java FX SDK: Java FX compiler and runtime tools. Graphics, media web services, and rich text libraries
2. Net Beans IDE for JavaFX: Net Beans with drag-and-drop palette to add objects with transformations, effects and animations plus set of samples and best practices. For Eclipse users there is a community-supported plugin hosted on Project Kenai
3. Tools and plug-in for creative tools (a.k.a. Production Suite): Plugins for Adobe Photoshop and Adobe Illustrator that can export graphics assets to JavaFX Script code, tools to convert SVG graphics into JavaFX Script code and preview assets converted to JavaFX from other tools.
Technical highlights
Common profile. JavaFX is based on the concept of a Common profile that is intended to span across all devices supported by JavaFX. This approach makes it possible for developers to use a common programming model while building an application targeted for both desktop and mobile devices and to share much of the code, graphics assets and content between desktop and mobile versions. To address the need for tuning applications for the needs of specific class of devices, the JavaFX 1.1 platform includes APIs that are desktop or mobile-specific. For example JavaFX Desktop profile includes Swing and advanced visual effects.
Drag-to-Install. From the point of view of the end user Drag-to-Install allows them to drag a JavaFX widget or application residing in a website within the browser window and drop it onto their desktop. The application will not lose its state or context even after the browser is closed. An application can also be re-launched by clicking on a shortcut that gets automatically created on the user's desktop. This behavior is enabled out-of-the-box by the Java applet mechanism and is leveraged by JavaFX from the underlying Java layer. Sun touts Drag-to-Install as opening up of a new distribution model and allowing developers to break away from the browser.
Integrating graphics created with third-party tools. JavaFX includes a set of plug-ins for Adobe Photoshop and Illustrator that enable advanced graphics to be integrated directly into JavaFX applications. The plug-ins generate JavaFX Script code that preserves layers and structure of the graphics. Developers can then easily add animation or effects to the static graphics imported. There is also an SVG graphics converter tool (a.k.a. Media Factory) that allows for importing graphics and previewing assets after the conversion to JavaFX format.
JavaFX 1.1
JavaFX for mobile development was finally made available as part of the JavaFX 1.1 release announced officially on February 12 2009.
JavaFX 1.2
JavaFX 1.2 was released at JavaOne on June 2, 2009. This release introduced [3]:
* Full support for Linux and Solaris,
* Built-in controls and layouts,
* Skinnable CSS controls,
* Built-in chart widgets,
* JavaFX I/O management, masking differences between desktop and mobile devices,
* Speed improvements.
By - Ravi
Please find more topics under JASe Archive!!!
TIPS AND TRICKS
Java's First Garbage Collector
Sun released Java SE 6 Update 14, which included a version of the much-anticipated Garbage First (G1) garbage collector. G1 is a low-pause, low-latency, sometimes soft real-time, collector that allows you to set max pause time goals and collection intervals through suggestions on the Java VM command line. Although it cannot guarantee it, G1 will attempt to meet your goals, and hence introduce as little latency as possible into your application. This in turn may also make the VM run more predictably as it attempts to meet the pause time goals you provide.
Garbage-First is a server-style garbage collector, targeted for multi-processors with large memories, that meets a soft real-time goal with high probability. It does this while also achieving high throughput, which is an important point when comparing it to other real-time collectors.
The G1 collector divides its work into multiple phases, each described below, which operate on a heap broken down into equally sized regions. In the strictest sense, the heap doesn't contain generational areas, although a subset of the regions can be treated as such. This provides flexibility in how garbage collection is performed, which is adjusted on-the-fly according to the amount of processor time available to the collector.
By – Chaitanya
Open Source Load Testing Tool for Java Applications (JMeter)
This is an Ant task for automating running JMeter test plans. The task executes one or more JMeter test plans, and logs the results to a file.
To use the task, you must have JMeter installed. You must also include ant-jmeter-1.0.9.jar in your Ant class path. Adding the jar to $ANT_HOME/lib will make this happen automatically.
Start by defining the task to make it available to your build script:
name="jmeter"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
Set the jmeterhome parameter to your JMeter install location, and the resultlog parameter to the name of a file to log the test results to.
You can either specify a single test plan using the testplan parameter, or multiple test plans using the testplans nested element. The testplans element is a standard Ant FileSet element.
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl"/>
jmeterhome="c:\jakarta-jmeter-1.8.1"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
Optional JMeter arguments supported include specifying an alternate jmeter properties file (jmeterproperties), running remote servers specified in jmeter properties file (runremote), and running the tests through a proxy or firewall (proxyhost, proxyport, proxyuser, proxypass).
Setting the failureProperty attribute will set the specified property to "true" in the event of a JMeter test failure. This gives you the opportunity to take further action such as send an email or fail the build.
You can override JMeter properties (instead of modifying jmeter.properties) like this:
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
You may also specify additional JVM arguments to the JVM launched to run JMeter. Here is an example of how to specify JVM arguments:
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
I've also included an XSLT file, jmeter-results-report.xsl, for generating a summary report from the result log file. The summary report is very similar to the default report created by the junitreport task. You can use the xslt task to create the report:
in="${basedir}/loadtests/JMeterResults.jtl"
out="${basedir}/loadtests/JMeterResults.html"
style="${basedir}/loadtests/jmeter-results-report.xsl"/>
Note: If you are using JMeter 2.1 or later, you must use the new xslt stylesheet(s) included in the JMeter extras directory. The new stylesheets have been modified to support the new JMeter log file format.
If you would like failure detail messages in the report output, you must configure JMeter to output that information to the result log. To do this, set the following property in your jmeter.properties file before running the test plans:
jmeter.save.saveservice.assertion_results=all
Note: As of JMeter 1.9RC2 (?), the default results output format is now csv. It must be changed to xml in order to use the xslt task to create the html report
By – Bavan
How to improve Java's I/O performance
The JDK 1.0.2 java.io package has meant problems for I/O performance, but here's a tip for making the situation better -- plus an extra tip on turning off synchronization
Java's I/O performance has been a bottleneck for a lot of Java applications because of a poorly designed and implemented JDK 1.0.2 java.io package. A key problem is buffer -- most classes in java.io are not buffered. In fact, the only classes with buffers are BufferedInputStream and BufferedOutputStream, but they provide very limited methods. For example, in most file-related applications, you need to parse a file line by line. But the only class that provides the readLine method is the DataInputStream, and it has no internal buffer. The readLine method in the DataInputStream class actually reads the input stream character by character until it hits a "\n" or "\r\n". Each character-read operation involves file I/O. This is extremely inefficient when reading a large file. A 5-megabyte file requires at least 5 million character-read file I/O operations when no buffer is provided.
The new JDK 1.1 improves I/O performance with the addition of a collection of Reader and Writer classes. The readLine method in BufferedReader is at least 10 to 20 times faster than the one in DataInputStream when a large file is encountered. Unfortunately, JDK 1.1 does not solve all the performance problems. For example, RandomAccessFile is a very useful class when you want to parse a large file and do not want to read it into memory. Still it is not buffered in JDK 1.1, and no equivalent Reader class has been provided.
By – Arun GJ
Please find more topics under JASe Archive!!!
Sun released Java SE 6 Update 14, which included a version of the much-anticipated Garbage First (G1) garbage collector. G1 is a low-pause, low-latency, sometimes soft real-time, collector that allows you to set max pause time goals and collection intervals through suggestions on the Java VM command line. Although it cannot guarantee it, G1 will attempt to meet your goals, and hence introduce as little latency as possible into your application. This in turn may also make the VM run more predictably as it attempts to meet the pause time goals you provide.
Garbage-First is a server-style garbage collector, targeted for multi-processors with large memories, that meets a soft real-time goal with high probability. It does this while also achieving high throughput, which is an important point when comparing it to other real-time collectors.
The G1 collector divides its work into multiple phases, each described below, which operate on a heap broken down into equally sized regions. In the strictest sense, the heap doesn't contain generational areas, although a subset of the regions can be treated as such. This provides flexibility in how garbage collection is performed, which is adjusted on-the-fly according to the amount of processor time available to the collector.
By – Chaitanya
Open Source Load Testing Tool for Java Applications (JMeter)
This is an Ant task for automating running JMeter test plans. The task executes one or more JMeter test plans, and logs the results to a file.
To use the task, you must have JMeter installed. You must also include ant-jmeter-1.0.9.jar in your Ant class path. Adding the jar to $ANT_HOME/lib will make this happen automatically.
Start by defining the task to make it available to your build script:
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
Set the jmeterhome parameter to your JMeter install location, and the resultlog parameter to the name of a file to log the test results to.
You can either specify a single test plan using the testplan parameter, or multiple test plans using the testplans nested element. The testplans element is a standard Ant FileSet element.
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl"/>
resultlog="${basedir}/loadtests/JMeterResults.jtl">
Optional JMeter arguments supported include specifying an alternate jmeter properties file (jmeterproperties), running remote servers specified in jmeter properties file (runremote), and running the tests through a proxy or firewall (proxyhost, proxyport, proxyuser, proxypass).
Setting the failureProperty attribute will set the specified property to "true" in the event of a JMeter test failure. This gives you the opportunity to take further action such as send an email or fail the build.
You can override JMeter properties (instead of modifying jmeter.properties) like this:
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
You may also specify additional JVM arguments to the JVM launched to run JMeter. Here is an example of how to specify JVM arguments:
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
I've also included an XSLT file, jmeter-results-report.xsl, for generating a summary report from the result log file. The summary report is very similar to the default report created by the junitreport task. You can use the xslt task to create the report:
out="${basedir}/loadtests/JMeterResults.html"
style="${basedir}/loadtests/jmeter-results-report.xsl"/>
Note: If you are using JMeter 2.1 or later, you must use the new xslt stylesheet(s) included in the JMeter extras directory. The new stylesheets have been modified to support the new JMeter log file format.
If you would like failure detail messages in the report output, you must configure JMeter to output that information to the result log. To do this, set the following property in your jmeter.properties file before running the test plans:
jmeter.save.saveservice.assertion_results=all
Note: As of JMeter 1.9RC2 (?), the default results output format is now csv. It must be changed to xml in order to use the xslt task to create the html report
By – Bavan
How to improve Java's I/O performance
The JDK 1.0.2 java.io package has meant problems for I/O performance, but here's a tip for making the situation better -- plus an extra tip on turning off synchronization
Java's I/O performance has been a bottleneck for a lot of Java applications because of a poorly designed and implemented JDK 1.0.2 java.io package. A key problem is buffer -- most classes in java.io are not buffered. In fact, the only classes with buffers are BufferedInputStream and BufferedOutputStream, but they provide very limited methods. For example, in most file-related applications, you need to parse a file line by line. But the only class that provides the readLine method is the DataInputStream, and it has no internal buffer. The readLine method in the DataInputStream class actually reads the input stream character by character until it hits a "\n" or "\r\n". Each character-read operation involves file I/O. This is extremely inefficient when reading a large file. A 5-megabyte file requires at least 5 million character-read file I/O operations when no buffer is provided.
The new JDK 1.1 improves I/O performance with the addition of a collection of Reader and Writer classes. The readLine method in BufferedReader is at least 10 to 20 times faster than the one in DataInputStream when a large file is encountered. Unfortunately, JDK 1.1 does not solve all the performance problems. For example, RandomAccessFile is a very useful class when you want to parse a large file and do not want to read it into memory. Still it is not buffered in JDK 1.1, and no equivalent Reader class has been provided.
By – Arun GJ
Please find more topics under JASe Archive!!!
Tuesday, September 15, 2009
WHAT'S NEW IN JAVA
JAVAFX
What is JavaFx
JavaFX is a software platform for creating and delivering rich Internet applications that can run across wide variety of connected devices. The current release (JavaFX 1.2, June 2009) enables building applications for desktop, browser and mobile phones. TV set-top boxes, gaming consoles, Blu-ray players and other platforms are planned
Over View
JavaFX is an expressive client platform for creating and delivering rich Internet experiences across all screens of your life. It combines the best capabilities of the Java platform with comprehensive, immersive media functionality into an intuitive and comprehensive, one-stop development environment.
Features
* Provides a unified development and deployment model for building rich client applications
* Enables you to easily integrate audio and video, graphics, rich text, and Web services
* Allows creative developers to program in a visual context
* Provides tools to build and deliver rich Internet applications for desktop, mobile, TV, and other consumer platforms
* Enables unprecedented collaboration between designers and developers
* Allows designers and Java developers to easily leverage the best of today's advanced enterprise software and rich Internet applications
Technology
JavaFX provides a productive development environment for web developers, mashup authors, and Java developers to quickly and easily build the next generation of rich internet applications (RIAs). With JavaFX, designers and developers can collaborate on building high-impact RIAs. Designers gain a broad set of tools to complete the designer/developer workflow, and developers have a simple, declarative scripting language with the right set of tools.
Latest Version
Java fx1.2 SDK
Current Release
1. The Java FX SDK: Java FX compiler and runtime tools. Graphics, media web services, and rich text libraries
2. Net Beans IDE for JavaFX: Net Beans with drag-and-drop palette to add objects with transformations, effects and animations plus set of samples and best practices. For Eclipse users there is a community-supported plugin hosted on Project Kenai
3. Tools and plug-in for creative tools (a.k.a. Production Suite): Plugins for Adobe Photoshop and Adobe Illustrator that can export graphics assets to JavaFX Script code, tools to convert SVG graphics into JavaFX Script code and preview assets converted to JavaFX from other tools.
Technical highlights
Common profile. JavaFX is based on the concept of a Common profile that is intended to span across all devices supported by JavaFX. This approach makes it possible for developers to use a common programming model while building an application targeted for both desktop and mobile devices and to share much of the code, graphics assets and content between desktop and mobile versions. To address the need for tuning applications for the needs of specific class of devices, the JavaFX 1.1 platform includes APIs that are desktop or mobile-specific. For example JavaFX Desktop profile includes Swing and advanced visual effects.
Drag-to-Install. From the point of view of the end user Drag-to-Install allows them to drag a JavaFX widget or application residing in a website within the browser window and drop it onto their desktop. The application will not lose its state or context even after the browser is closed. An application can also be re-launched by clicking on a shortcut that gets automatically created on the user's desktop. This behavior is enabled out-of-the-box by the Java applet mechanism and is leveraged by JavaFX from the underlying Java layer. Sun touts Drag-to-Install as opening up of a new distribution model and allowing developers to break away from the browser.
Integrating graphics created with third-party tools. JavaFX includes a set of plug-ins for Adobe Photoshop and Illustrator that enable advanced graphics to be integrated directly into JavaFX applications. The plug-ins generate JavaFX Script code that preserves layers and structure of the graphics. Developers can then easily add animation or effects to the static graphics imported. There is also an SVG graphics converter tool (a.k.a. Media Factory) that allows for importing graphics and previewing assets after the conversion to JavaFX format.
JavaFX 1.1
JavaFX for mobile development was finally made available as part of the JavaFX 1.1 release announced officially on February 12 2009.
JavaFX 1.2
JavaFX 1.2 was released at JavaOne on June 2, 2009. This release introduced [3]:
* Full support for Linux and Solaris,
* Built-in controls and layouts,
* Skinnable CSS controls,
* Built-in chart widgets,
* JavaFX I/O management, masking differences between desktop and mobile devices,
* Speed improvements.
By - Ravi
Please find more topics under JASe Archive!!!
What is JavaFx
JavaFX is a software platform for creating and delivering rich Internet applications that can run across wide variety of connected devices. The current release (JavaFX 1.2, June 2009) enables building applications for desktop, browser and mobile phones. TV set-top boxes, gaming consoles, Blu-ray players and other platforms are planned
Over View
JavaFX is an expressive client platform for creating and delivering rich Internet experiences across all screens of your life. It combines the best capabilities of the Java platform with comprehensive, immersive media functionality into an intuitive and comprehensive, one-stop development environment.
Features
* Provides a unified development and deployment model for building rich client applications
* Enables you to easily integrate audio and video, graphics, rich text, and Web services
* Allows creative developers to program in a visual context
* Provides tools to build and deliver rich Internet applications for desktop, mobile, TV, and other consumer platforms
* Enables unprecedented collaboration between designers and developers
* Allows designers and Java developers to easily leverage the best of today's advanced enterprise software and rich Internet applications
Technology
JavaFX provides a productive development environment for web developers, mashup authors, and Java developers to quickly and easily build the next generation of rich internet applications (RIAs). With JavaFX, designers and developers can collaborate on building high-impact RIAs. Designers gain a broad set of tools to complete the designer/developer workflow, and developers have a simple, declarative scripting language with the right set of tools.
Latest Version
Java fx1.2 SDK
Current Release
1. The Java FX SDK: Java FX compiler and runtime tools. Graphics, media web services, and rich text libraries
2. Net Beans IDE for JavaFX: Net Beans with drag-and-drop palette to add objects with transformations, effects and animations plus set of samples and best practices. For Eclipse users there is a community-supported plugin hosted on Project Kenai
3. Tools and plug-in for creative tools (a.k.a. Production Suite): Plugins for Adobe Photoshop and Adobe Illustrator that can export graphics assets to JavaFX Script code, tools to convert SVG graphics into JavaFX Script code and preview assets converted to JavaFX from other tools.
Technical highlights
Common profile. JavaFX is based on the concept of a Common profile that is intended to span across all devices supported by JavaFX. This approach makes it possible for developers to use a common programming model while building an application targeted for both desktop and mobile devices and to share much of the code, graphics assets and content between desktop and mobile versions. To address the need for tuning applications for the needs of specific class of devices, the JavaFX 1.1 platform includes APIs that are desktop or mobile-specific. For example JavaFX Desktop profile includes Swing and advanced visual effects.
Drag-to-Install. From the point of view of the end user Drag-to-Install allows them to drag a JavaFX widget or application residing in a website within the browser window and drop it onto their desktop. The application will not lose its state or context even after the browser is closed. An application can also be re-launched by clicking on a shortcut that gets automatically created on the user's desktop. This behavior is enabled out-of-the-box by the Java applet mechanism and is leveraged by JavaFX from the underlying Java layer. Sun touts Drag-to-Install as opening up of a new distribution model and allowing developers to break away from the browser.
Integrating graphics created with third-party tools. JavaFX includes a set of plug-ins for Adobe Photoshop and Illustrator that enable advanced graphics to be integrated directly into JavaFX applications. The plug-ins generate JavaFX Script code that preserves layers and structure of the graphics. Developers can then easily add animation or effects to the static graphics imported. There is also an SVG graphics converter tool (a.k.a. Media Factory) that allows for importing graphics and previewing assets after the conversion to JavaFX format.
JavaFX 1.1
JavaFX for mobile development was finally made available as part of the JavaFX 1.1 release announced officially on February 12 2009.
JavaFX 1.2
JavaFX 1.2 was released at JavaOne on June 2, 2009. This release introduced [3]:
* Full support for Linux and Solaris,
* Built-in controls and layouts,
* Skinnable CSS controls,
* Built-in chart widgets,
* JavaFX I/O management, masking differences between desktop and mobile devices,
* Speed improvements.
By - Ravi
Please find more topics under JASe Archive!!!
PRODUCT AND TECHNOLOGY RELEASES
IBM Real Time Application Execution Optimizer for Java
IBM Real Time Application Execution Optimizer for Java helps to optimize and verify a compiled Java application, preparing the application for deployment in specific environments. It is a command line tool that can operate on any compiled Java application, whether standard edition, micro-edition, or real-time.
The tool provides the following functions:
•Escape analysis of objects per method invocation
•Control flow analysis that splits an application into archives according to thread accessibility
•Control flow analysis that detects potental occurrences of real-time java runtime errors MemoryAccessError, IllegalAssignmentError, IllegalThreadStateException
•Control flow analysis that determines entry points into an application
•Addition of stackmaps to Java class files
•Verification of Java class files
•Auto-generation of classes that will load and initialize all other classes within the same archive
•Specialized packaging of Java applications into deployable archives by packaging all referenced classes from a dual class path
•Removal of unwanted attributes from Java class files
Working Principle
IBM Real Time Application Execution Optimizer for Java has many features. It loads the classes and resources of an application, analyzes or modifies them, then it writes them to disk along with any requested analysis files.
While loading the application, all classes needed for deployment of the application are identified and loaded. Also identified are all unresolved references. An unresolved reference is a class, method or field that cannot be found. Each class is checked for all possible class loading, resolution, and verification errors. This can be helpful to verify classes that are not produced by standard compilers and to ensure no application components are missing.
The tool separates application classes into the following categories:
• NoHeapRealtimeThread (NHRT) accessible
• RealtimeThread accessible
• Regular thread accessible
• Inaccessible: classes not accessible to any thread.
Once separated, the tool will package these class groups into separate archives for specialized deployment when the classes are written to disk. It will package resources into an additional archive.
While analyzing the control flow of the application, the tool identifies all entry points into the application, which are the classes, methods or fields that can be accessed from outside the application. For example, it will detect methods that can be invoked in application classes from external classes because they override external methods.
It verifies the integrity of real-time Java memory usage in the application, by detecting the potential run-time errors MemoryAccessError, IllegalAssignmentError and IllegalThreadStateException which are common errors that are difficult to eliminate when developing real-time Java.
Escape analysis is used by the tool to determine the persistent memory characteristics of allocated objects within the application on a per-invocation basis. For each method, an escape analysis determines whether the objects created by invocations of the method can persist. This helps identify memory requirements for the heap, for scopes, and for other memory areas in use.
While writing classes, to disk, the tool can remove unwanted class file attributes (such as attributes needed only for debugging), and adds stackmaps to classes. This can assist with run-time memory consumption constraints.
The tool can add to each written archive an auto-loader class that will load and initialize all other classes within the same archive, in order to trigger early class initialization for an application.
By - Sankarasivan
Java Server Faces
Java Server Faces technology is a framework for building user interfaces for web applications.
Java Server Faces technology includes:
Java APIs to represent UI components, manage state, handle events, and validate input. The API has support for internationalization and accessibility.
Two JSP custom tag libraries for expressing user interface (UI) components within a JSP page, and for wiring components to server-side objects. Page authors can easily add UI components to their pages.
Java Server Faces technology is based on the Model View Controller (MVC) architecture for separating logic from presentation, so if you have been practicing this, you'll feel at home with JSF.
A JSF application is just like any other Java technology-based web application; it runs in a Java Servlet container, and contains:
JavaBeans components (or model objects) containing application-specific functionality and data
Event listeners -- JSP pages
Server-side helper classes
A custom tag library for rendering UI components
A custom tag library for representing event handlers and validators
UI components represented as stateful objects on the server
Validators, event handlers, and navigation handlers.
Application configuration resource file for configuring application resources
How to Create a Java Server Faces (JSF) Development Environment w Apache Tomcat + Suns JDK
By - Feizal
Please find more topics under JASe Archive!!!
IBM Real Time Application Execution Optimizer for Java helps to optimize and verify a compiled Java application, preparing the application for deployment in specific environments. It is a command line tool that can operate on any compiled Java application, whether standard edition, micro-edition, or real-time.
The tool provides the following functions:
•Escape analysis of objects per method invocation
•Control flow analysis that splits an application into archives according to thread accessibility
•Control flow analysis that detects potental occurrences of real-time java runtime errors MemoryAccessError, IllegalAssignmentError, IllegalThreadStateException
•Control flow analysis that determines entry points into an application
•Addition of stackmaps to Java class files
•Verification of Java class files
•Auto-generation of classes that will load and initialize all other classes within the same archive
•Specialized packaging of Java applications into deployable archives by packaging all referenced classes from a dual class path
•Removal of unwanted attributes from Java class files
Working Principle
IBM Real Time Application Execution Optimizer for Java has many features. It loads the classes and resources of an application, analyzes or modifies them, then it writes them to disk along with any requested analysis files.
While loading the application, all classes needed for deployment of the application are identified and loaded. Also identified are all unresolved references. An unresolved reference is a class, method or field that cannot be found. Each class is checked for all possible class loading, resolution, and verification errors. This can be helpful to verify classes that are not produced by standard compilers and to ensure no application components are missing.
The tool separates application classes into the following categories:
• NoHeapRealtimeThread (NHRT) accessible
• RealtimeThread accessible
• Regular thread accessible
• Inaccessible: classes not accessible to any thread.
Once separated, the tool will package these class groups into separate archives for specialized deployment when the classes are written to disk. It will package resources into an additional archive.
While analyzing the control flow of the application, the tool identifies all entry points into the application, which are the classes, methods or fields that can be accessed from outside the application. For example, it will detect methods that can be invoked in application classes from external classes because they override external methods.
It verifies the integrity of real-time Java memory usage in the application, by detecting the potential run-time errors MemoryAccessError, IllegalAssignmentError and IllegalThreadStateException which are common errors that are difficult to eliminate when developing real-time Java.
Escape analysis is used by the tool to determine the persistent memory characteristics of allocated objects within the application on a per-invocation basis. For each method, an escape analysis determines whether the objects created by invocations of the method can persist. This helps identify memory requirements for the heap, for scopes, and for other memory areas in use.
While writing classes, to disk, the tool can remove unwanted class file attributes (such as attributes needed only for debugging), and adds stackmaps to classes. This can assist with run-time memory consumption constraints.
The tool can add to each written archive an auto-loader class that will load and initialize all other classes within the same archive, in order to trigger early class initialization for an application.
By - Sankarasivan
Java Server Faces
Java Server Faces technology is a framework for building user interfaces for web applications.
Java Server Faces technology includes:
Java APIs to represent UI components, manage state, handle events, and validate input. The API has support for internationalization and accessibility.
Two JSP custom tag libraries for expressing user interface (UI) components within a JSP page, and for wiring components to server-side objects. Page authors can easily add UI components to their pages.
Java Server Faces technology is based on the Model View Controller (MVC) architecture for separating logic from presentation, so if you have been practicing this, you'll feel at home with JSF.
A JSF application is just like any other Java technology-based web application; it runs in a Java Servlet container, and contains:
JavaBeans components (or model objects) containing application-specific functionality and data
Event listeners -- JSP pages
Server-side helper classes
A custom tag library for rendering UI components
A custom tag library for representing event handlers and validators
UI components represented as stateful objects on the server
Validators, event handlers, and navigation handlers.
Application configuration resource file for configuring application resources
How to Create a Java Server Faces (JSF) Development Environment w Apache Tomcat + Suns JDK
By - Feizal
Please find more topics under JASe Archive!!!
TIPS AND TRICKS
Comparing Constant Strings with String Variables
To avoid problems, you should never compare a string variable with a string constant, because string variables may have a null value, in which case your code will throw a NullPointerException. Here's an example:
String strName = null;
strName = getName(); //some call which retrives name from DB
if(strName.equals("Ritesh Patel")) {
// some processing.
}
The preceding example might raise an exception if the result of the getName() call returns null. Instead, to be safe, always make the comparison the other way around—by comparing the string constant with the string variable:
String strName = null;
strName = getName();
if("Ritesh Patel".equals(strName)) {
// some processing.
}
Following this rule will help you avoid unnecessary NullPointerExceptions and abnormal program termination.
By - Bavanandan
List of J2EE Patterns Catalog
Below is the list of available J2EE Patterns and their description
Business Delegate
Reduce coupling between Web and Enterprise JavaBeans TM tiers
Composite Entity
Model a network of related business entities
Composite View
Separately manage layout and content of multiple composed views
Data Access Object (DAO)
Abstract and encapsulate data access mechanisms
Fast Lane Reader
Improve read performance of tabular data
Front Controller
Centralize application request processing
Intercepting Filter
Pre- and post-process application requests
Model-View-Controller
Decouple data representation, application behavior, and presentation
Service Locator
Simplify client access to enterprise business services
Session Facade
Coordinate operations between multiple business objects in a workflow
Transfer Object
Transfer business data between tiers
Value List Handler
Efficiently iterate a virtual list
View Helper
Simplify access to model state and data access logic
By - Feizal
Java Design Patterns
Abstract: “Pattern” as the name suggests, means series of events occurring in a definite order. The patterns can be found in Java and J2ee technologies also. Many a times, we find that there is a particular way of tackling a problem. This way is easy and has been used many times successfully by a number of people earlier also. This method becomes a pattern.
Creational Patterns
There are five types of Creational Patterns.
1. Factory Pattern
2. Abstract Factory Pattern
3. Builder Pattern
4. Prototype Pattern
5. Singleton Pattern
Structural Patterns
Structural Patterns describe how objects and classes can be combined to form larger structures. The difference between class patterns and object patterns is that class patterns describe abstraction with the help of inheritance and how it can be used to provide more useful program interface. Object patterns, on other hand, describe how objects can be associated and composed to form larger, more complex structures.
There are seven structural patterns described. They are as follows:
Patterns.
1. Adapter Pattern
2. Bridge Pattern
3. Composite Pattern
4. Decorator Pattern
5. Facade Pattern
6. Flyweight Pattern
7. Proxy Pattern
Behavioral Patterns
Behavioral patterns are those which are concerned with interactions between the objects. The interactions between the objects should be such that they are talking to each other and still are loosely coupled. The loose coupling is the key to n-tier architectures. In this, the implementation and the client should be loosely coupled in order to avoid hard-coding and dependencies.
The behavioral patterns are:
1. Chain of Resposibility Pattern
2. Command Pattern
3. Interpreter Pattern
4. Iterator Pattern
5. Mediator Pattern
6. Momento Pattern
7. Observer Pattern
8. State Pattern
9. Strategy Pattern
10. Template Pattern
11. Visitor Pattern
By - Amaresh
Please find more topics under JASe Archive!!!
To avoid problems, you should never compare a string variable with a string constant, because string variables may have a null value, in which case your code will throw a NullPointerException. Here's an example:
String strName = null;
strName = getName(); //some call which retrives name from DB
if(strName.equals("Ritesh Patel")) {
// some processing.
}
The preceding example might raise an exception if the result of the getName() call returns null. Instead, to be safe, always make the comparison the other way around—by comparing the string constant with the string variable:
String strName = null;
strName = getName();
if("Ritesh Patel".equals(strName)) {
// some processing.
}
Following this rule will help you avoid unnecessary NullPointerExceptions and abnormal program termination.
By - Bavanandan
List of J2EE Patterns Catalog
Below is the list of available J2EE Patterns and their description
Business Delegate
Reduce coupling between Web and Enterprise JavaBeans TM tiers
Composite Entity
Model a network of related business entities
Composite View
Separately manage layout and content of multiple composed views
Data Access Object (DAO)
Abstract and encapsulate data access mechanisms
Fast Lane Reader
Improve read performance of tabular data
Front Controller
Centralize application request processing
Intercepting Filter
Pre- and post-process application requests
Model-View-Controller
Decouple data representation, application behavior, and presentation
Service Locator
Simplify client access to enterprise business services
Session Facade
Coordinate operations between multiple business objects in a workflow
Transfer Object
Transfer business data between tiers
Value List Handler
Efficiently iterate a virtual list
View Helper
Simplify access to model state and data access logic
By - Feizal
Java Design Patterns
Abstract: “Pattern” as the name suggests, means series of events occurring in a definite order. The patterns can be found in Java and J2ee technologies also. Many a times, we find that there is a particular way of tackling a problem. This way is easy and has been used many times successfully by a number of people earlier also. This method becomes a pattern.
Creational Patterns
There are five types of Creational Patterns.
1. Factory Pattern
2. Abstract Factory Pattern
3. Builder Pattern
4. Prototype Pattern
5. Singleton Pattern
Structural Patterns
Structural Patterns describe how objects and classes can be combined to form larger structures. The difference between class patterns and object patterns is that class patterns describe abstraction with the help of inheritance and how it can be used to provide more useful program interface. Object patterns, on other hand, describe how objects can be associated and composed to form larger, more complex structures.
There are seven structural patterns described. They are as follows:
Patterns.
1. Adapter Pattern
2. Bridge Pattern
3. Composite Pattern
4. Decorator Pattern
5. Facade Pattern
6. Flyweight Pattern
7. Proxy Pattern
Behavioral Patterns
Behavioral patterns are those which are concerned with interactions between the objects. The interactions between the objects should be such that they are talking to each other and still are loosely coupled. The loose coupling is the key to n-tier architectures. In this, the implementation and the client should be loosely coupled in order to avoid hard-coding and dependencies.
The behavioral patterns are:
1. Chain of Resposibility Pattern
2. Command Pattern
3. Interpreter Pattern
4. Iterator Pattern
5. Mediator Pattern
6. Momento Pattern
7. Observer Pattern
8. State Pattern
9. Strategy Pattern
10. Template Pattern
11. Visitor Pattern
By - Amaresh
Please find more topics under JASe Archive!!!
Monday, August 31, 2009
WHAT'S NEW IN JAVA
JDK 7
Java Development Kit 7 (JDK 7) is the next major release of the Java SE platform. Through the Open JDK project, JDK 7 has been a highly collaborative effort between Sun and volunteers from the Java developer community. Sun extends its gratitude to all who have contributed to this release.
Learn about some of the new and cool features in the next release of the Java Development Kit, JDK 7.
In this Deep Dive, Danny Coward, Chief Architect for Client Software at Sun Microsystems, highlighted some of the significant new features in JDK 7. Some of these features focus on modularizing the JDK, supporting non-Java languages at the VM level, and making developers more productive through various small changes to the Java languages. Danny backed up this discussion with some code examples and demonstrations.
JDK 7 introduces several key features to improve performance, usability, and security of the Java platform. A detailed list of these features appears on the Open JDK site.
Based on the feedback from the developer community and Sun's customers, the JDK 7 features primarily focus on the following areas.
Features
This is the list of features being developed by Sun, and others, for JDK 7.
When the Java SE 7 Platform JSR is submitted then these features will be proposed therein, except for those listed as either VM-level or implementation-specific.
Per the draft of the development process we will shortly publish a Feature Proposal template. That will be the vehicle for proposing additional features for inclusion in the release. Smaller, non-feature changes will go through a lighter-weight process, soon to be defined.
JDK 7 Development Process
In the continuing transition of JDK development activities to a more
open, collaborative model, we're going to completely revise the JDK
development process. The sketch presented here is based on the past
thirteen years of the Sun JDK team's experience, seasoned by ideas and
lessons learned from other, mainly non-Sun projects.
This is just a first draft. There's no one obviously "right" way to
design this sort of process; this is a starting point. Comments are,
as always, most welcome: jdk7-dev at openjdk dot java dot net.
This process is more involved than that of many free-software or
open-source projects. This is a result of the JDK team's strong
commitment to the highest standards of quality, compatibility, and
performance, and also the fact that we're maintaining and evolving not
just a large body of code but, simultaneously, the specification of one
of the world's most widely-used programming platforms.
Ultimately we will leverage our new Bugzilla instance to automate the
tracking of the various review and approval paths defined here. That's
an implementation detail, however; for now let's focus on getting the
process into a workable form.
Modularization
A large-scale effort to re factor, or break up, the Java SE platform into smaller, separate, interdependent modules. Individual modules can then be downloaded as required by the Java virtual machine and/or Java applications. This effectively shrinks the size of the runtime on the user's machine.
One benefit of modularization is that the platform is a smaller download, potentially improving start-up performance. Having a smaller memory footprint also enables significant performance improvements, especially for desktop applications. A smaller platform also means it can now fit on devices with less memory.
Multi-Language Support
Improves compatibility between Java and various dynamic languages, such as Ruby and Python, by providing better-than-native implementations of these languages on top of the Java Runtime Environment (JRE).
Refer to JSR 292, also called "Invoke Dynamic". This JSR defines the elements critical for Ruby, Python, and other dynamic languages to be addressed for JDK 7.
Developer Productivity
JDK 7 will also include several features to enhance developer productivity. One of Sun's goals is to make JDK 7, and other versions of the JDK, as developer-friendly as possible.
Performance
Sun understands the need to improve the performance of the Java SE platform, and several features in JDK 7 address just that.
The new Garbage First (G1) Garbage Collector is a low pause, server-style garbage collector that will eventually replace the Concurrent Mark-Sweep (CMS) garbage collector. G1's primary advantage over CMS is incremental compaction, better predictability, and ease of use.
Click here for more information.
By - Ramesh
Please find more topics under JASe Archive!!!
Java Development Kit 7 (JDK 7) is the next major release of the Java SE platform. Through the Open JDK project, JDK 7 has been a highly collaborative effort between Sun and volunteers from the Java developer community. Sun extends its gratitude to all who have contributed to this release.
Learn about some of the new and cool features in the next release of the Java Development Kit, JDK 7.
In this Deep Dive, Danny Coward, Chief Architect for Client Software at Sun Microsystems, highlighted some of the significant new features in JDK 7. Some of these features focus on modularizing the JDK, supporting non-Java languages at the VM level, and making developers more productive through various small changes to the Java languages. Danny backed up this discussion with some code examples and demonstrations.
JDK 7 introduces several key features to improve performance, usability, and security of the Java platform. A detailed list of these features appears on the Open JDK site.
Based on the feedback from the developer community and Sun's customers, the JDK 7 features primarily focus on the following areas.
Features
This is the list of features being developed by Sun, and others, for JDK 7.
When the Java SE 7 Platform JSR is submitted then these features will be proposed therein, except for those listed as either VM-level or implementation-specific.
Per the draft of the development process we will shortly publish a Feature Proposal template. That will be the vehicle for proposing additional features for inclusion in the release. Smaller, non-feature changes will go through a lighter-weight process, soon to be defined.
JDK 7 Development Process
In the continuing transition of JDK development activities to a more
open, collaborative model, we're going to completely revise the JDK
development process. The sketch presented here is based on the past
thirteen years of the Sun JDK team's experience, seasoned by ideas and
lessons learned from other, mainly non-Sun projects.
This is just a first draft. There's no one obviously "right" way to
design this sort of process; this is a starting point. Comments are,
as always, most welcome: jdk7-dev at openjdk dot java dot net.
This process is more involved than that of many free-software or
open-source projects. This is a result of the JDK team's strong
commitment to the highest standards of quality, compatibility, and
performance, and also the fact that we're maintaining and evolving not
just a large body of code but, simultaneously, the specification of one
of the world's most widely-used programming platforms.
Ultimately we will leverage our new Bugzilla instance to automate the
tracking of the various review and approval paths defined here. That's
an implementation detail, however; for now let's focus on getting the
process into a workable form.
Modularization
A large-scale effort to re factor, or break up, the Java SE platform into smaller, separate, interdependent modules. Individual modules can then be downloaded as required by the Java virtual machine and/or Java applications. This effectively shrinks the size of the runtime on the user's machine.
One benefit of modularization is that the platform is a smaller download, potentially improving start-up performance. Having a smaller memory footprint also enables significant performance improvements, especially for desktop applications. A smaller platform also means it can now fit on devices with less memory.
Multi-Language Support
Improves compatibility between Java and various dynamic languages, such as Ruby and Python, by providing better-than-native implementations of these languages on top of the Java Runtime Environment (JRE).
Refer to JSR 292, also called "Invoke Dynamic". This JSR defines the elements critical for Ruby, Python, and other dynamic languages to be addressed for JDK 7.
Developer Productivity
JDK 7 will also include several features to enhance developer productivity. One of Sun's goals is to make JDK 7, and other versions of the JDK, as developer-friendly as possible.
Performance
Sun understands the need to improve the performance of the Java SE platform, and several features in JDK 7 address just that.
The new Garbage First (G1) Garbage Collector is a low pause, server-style garbage collector that will eventually replace the Concurrent Mark-Sweep (CMS) garbage collector. G1's primary advantage over CMS is incremental compaction, better predictability, and ease of use.
Click here for more information.
By - Ramesh
Please find more topics under JASe Archive!!!
PRODUCT AND TECHNOLOGY RELEASES
Java Server Faces
Java Server Faces technology is a framework for building user interfaces for web applications.
Java Server Faces technology includes:
Java APIs to represent UI components, manage state, handle events, and validate input. The API has support for internationalization and accessibility.
Two JSP custom tag libraries for expressing user interface (UI) components within a JSP page, and for wiring components to server-side objects. Page authors can easily add UI components to their pages.
Java Server Faces technology is based on the Model View Controller (MVC) architecture for separating logic from presentation, so if you have been practicing this, you'll feel at home with JSF.
A JSF application is just like any other Java technology-based web application; it runs in a Java Servlet container, and contains:
JavaBeans components (or model objects) containing application-specific functionality and data
Event listeners -- JSP pages
Server-side helper classes
A custom tag library for rendering UI components
A custom tag library for representing event handlers and validators
UI components represented as stateful objects on the server
Validators, event handlers, and navigation handlers.
Application configuration resource file for configuring application resources
One of the advantages of JSF is that it is based on the Model View Controller (MVC) architecture, to offer a clean separation between presentation and logic. This may ring a bell for those who are using existing web frameworks such as Struts. However, note that JSF and Struts are not competing technologies, and in fact, they interoperate together. JSF, however, does have some advantages over Struts.
For example, in Struts there is only one way to render an element, while JSF provides several mechanisms for rendering an individual element. It is up to the page designer to pick the desired representation, and the application developer doesn't need to know which mechanism was used to render a component
The author of Struts, Craig McClanahan, is also the co-specification lead for JSF, as well as an employee of Sun Microsystems.
Advantages
The primary benefits of Java Server Faces technology include:
Ease-of-Use: Several aspects of the Java Server Faces architecture contribute to its ease-of-use. For one, Java Server Faces technology offers a clean separation between logic and presentation, enabling a wide range of users -- from web-page designers to component developers-- to take advantage of Java Server technology, resulting in a division of labor and a shorter development cycle. Also, a user-interface created with Java Server Faces technology handles all the complexities of user-interface management, including input validation, component-state management, page navigation, and event handling.
Standardization: Java Server Faces technology is being developed through the Java Community Process. Several prominent, respected tools vendors are contributing members of the expert group and are committed to supporting Java Server Faces technology in their tools.
Device Independence: Java Server Faces technology is designed to be flexible. By defining only component functionality in extensible UI component classes, the Java Server Faces architecture allows component developers to extend the component classes to generate their own component tag libraries targeted for specific clients.
How to Create a Java Server Faces (JSF) Development Environment w Apache Tomcat + Suns JDK
By - Feizal
Please find more topics under JASe Archive!!!
Java Server Faces technology is a framework for building user interfaces for web applications.
Java Server Faces technology includes:
Java APIs to represent UI components, manage state, handle events, and validate input. The API has support for internationalization and accessibility.
Two JSP custom tag libraries for expressing user interface (UI) components within a JSP page, and for wiring components to server-side objects. Page authors can easily add UI components to their pages.
Java Server Faces technology is based on the Model View Controller (MVC) architecture for separating logic from presentation, so if you have been practicing this, you'll feel at home with JSF.
A JSF application is just like any other Java technology-based web application; it runs in a Java Servlet container, and contains:
JavaBeans components (or model objects) containing application-specific functionality and data
Event listeners -- JSP pages
Server-side helper classes
A custom tag library for rendering UI components
A custom tag library for representing event handlers and validators
UI components represented as stateful objects on the server
Validators, event handlers, and navigation handlers.
Application configuration resource file for configuring application resources
One of the advantages of JSF is that it is based on the Model View Controller (MVC) architecture, to offer a clean separation between presentation and logic. This may ring a bell for those who are using existing web frameworks such as Struts. However, note that JSF and Struts are not competing technologies, and in fact, they interoperate together. JSF, however, does have some advantages over Struts.
For example, in Struts there is only one way to render an element, while JSF provides several mechanisms for rendering an individual element. It is up to the page designer to pick the desired representation, and the application developer doesn't need to know which mechanism was used to render a component
The author of Struts, Craig McClanahan, is also the co-specification lead for JSF, as well as an employee of Sun Microsystems.
Advantages
The primary benefits of Java Server Faces technology include:
Ease-of-Use: Several aspects of the Java Server Faces architecture contribute to its ease-of-use. For one, Java Server Faces technology offers a clean separation between logic and presentation, enabling a wide range of users -- from web-page designers to component developers-- to take advantage of Java Server technology, resulting in a division of labor and a shorter development cycle. Also, a user-interface created with Java Server Faces technology handles all the complexities of user-interface management, including input validation, component-state management, page navigation, and event handling.
Standardization: Java Server Faces technology is being developed through the Java Community Process. Several prominent, respected tools vendors are contributing members of the expert group and are committed to supporting Java Server Faces technology in their tools.
Device Independence: Java Server Faces technology is designed to be flexible. By defining only component functionality in extensible UI component classes, the Java Server Faces architecture allows component developers to extend the component classes to generate their own component tag libraries targeted for specific clients.
How to Create a Java Server Faces (JSF) Development Environment w Apache Tomcat + Suns JDK
By - Feizal
Please find more topics under JASe Archive!!!
TIPS AND TRICKS
Generate PDF files from Java applications dynamically
Many applications demand dynamic generation of PDF documents. Such applications range from banks generating customer statements for e-mail delivery to readers buying specific book chapters and receiving them in PDF format.
Get familiar with iText
iText is a freely available Java library from Lowagie.com. The iText library is powerful and supports the generation of HTML, RTF, and XML documents, in addition to generating PDF's. You can choose from a variety of fonts to be used in the document. Also, the structure of iText allows you to generate any of the above-mentioned types of documents with the same code.
The iText library contains classes to generate PDF text in various fonts, generate tables in PDF document, add watermarks to pages, and so on. There are many more features available with iText. It would not be possible to demonstrate all of them in a single article. We will cover the basics required for PDF generation.
How to configure with Eclipse:
Downloading and configuring iText in Eclipse
Being a pure Java library, iText comes in the form of a JAR file which you download from Lowagie.com. Once you have downloaded the library (let's say, at path C:\temp), the following steps will configure the iText library in an Eclipse environment:
Create a new Java project in Eclipse named iText.
Right-click on the iText project in Package Explorer view and select Properties
Click Java Build Path. On the Libraries tab, click Add External Jar's.
Browse to the C:\temp directory and select the itext-1.3.jar in this directory.
Click OK.
iText is now configured, and Eclipse is ready to create Java applications to generate dynamic PDF documents.
By - Ramesh
Selecting the Best Java Collection Class for Your Application
• All Vector methods are synchronized as are Stack methods
• Array List fast operations are getting the size of the list, getting the object at a specified position in the list, and setting the object at a specified position in the list.
• Linked List can quickly insert or remove objects in the middle of the list whereas Array List takes time proportionate to the number of objects in the list after the position to which objects being added or removed. Use Array List unless you are inserting or deleting a lot from the middle of a list.
• If you rarely iterate an Array List object while it is being modified, then using a lock is a good solution. However, if iterating over a Array List while modifying it is common, then locking may make waiting time unacceptably high.
• With CopyOnWrite ArrayList all operations that change the contents of a CopyOnWriteArrayList collection cause the underlying array to be replaced with a copy of itself before the contents of the array are changed. Any active iterators will continue to see the unmodified array, so there is no need for locks.
• HashSet is faster than TreeSet, so only use the TreeSet preferentially when you need elements to remain in sorted order.
• HashSet is faster than LinkedHashSet so only use the LinkedHashSet preferentially when you need elements to remain in insertion order.
• ConcurrentSkipListSet keeps it's elements in sorted order and is thread-safe and usually preferable to a synchronized wrapped set.
• With CopyOnWriteArraySet all operations that change the contents of a CopyOnWriteArraySet collection cause the underlying array to be replaced with a copy of itself before the contents of the array are changed. Any active iterators will continue to see the unmodified array, so there is no need for locks.
• PriorityQueue add and remove methods take time that is proportionate to the number of objects in the queue. Queues based on the PriorityQueue class do not block. PriorityBlockingQueue is similar in performance but does block.
• DelayQueue is a specialized blocking queue that consults the objects it contains as to when they can be removed from the queue.
• A SynchronousQueue object is always empty; the put method blocks unless another thread is waiting for the object's take method to return.
• If you are not interested in how objects will be organized in a collection, then the only other consideration is performance. In that case, use the ArrayList class. It is fast and makes efficient use of memory.
By - Amaresh
Please find more topics under JASe Archive!!!
Many applications demand dynamic generation of PDF documents. Such applications range from banks generating customer statements for e-mail delivery to readers buying specific book chapters and receiving them in PDF format.
Get familiar with iText
iText is a freely available Java library from Lowagie.com. The iText library is powerful and supports the generation of HTML, RTF, and XML documents, in addition to generating PDF's. You can choose from a variety of fonts to be used in the document. Also, the structure of iText allows you to generate any of the above-mentioned types of documents with the same code.
The iText library contains classes to generate PDF text in various fonts, generate tables in PDF document, add watermarks to pages, and so on. There are many more features available with iText. It would not be possible to demonstrate all of them in a single article. We will cover the basics required for PDF generation.
How to configure with Eclipse:
Downloading and configuring iText in Eclipse
Being a pure Java library, iText comes in the form of a JAR file which you download from Lowagie.com. Once you have downloaded the library (let's say, at path C:\temp), the following steps will configure the iText library in an Eclipse environment:
Create a new Java project in Eclipse named iText.
Right-click on the iText project in Package Explorer view and select Properties
Click Java Build Path. On the Libraries tab, click Add External Jar's.
Browse to the C:\temp directory and select the itext-1.3.jar in this directory.
Click OK.
iText is now configured, and Eclipse is ready to create Java applications to generate dynamic PDF documents.
By - Ramesh
Selecting the Best Java Collection Class for Your Application
• All Vector methods are synchronized as are Stack methods
• Array List fast operations are getting the size of the list, getting the object at a specified position in the list, and setting the object at a specified position in the list.
• Linked List can quickly insert or remove objects in the middle of the list whereas Array List takes time proportionate to the number of objects in the list after the position to which objects being added or removed. Use Array List unless you are inserting or deleting a lot from the middle of a list.
• If you rarely iterate an Array List object while it is being modified, then using a lock is a good solution. However, if iterating over a Array List while modifying it is common, then locking may make waiting time unacceptably high.
• With CopyOnWrite ArrayList all operations that change the contents of a CopyOnWriteArrayList collection cause the underlying array to be replaced with a copy of itself before the contents of the array are changed. Any active iterators will continue to see the unmodified array, so there is no need for locks.
• HashSet is faster than TreeSet, so only use the TreeSet preferentially when you need elements to remain in sorted order.
• HashSet is faster than LinkedHashSet so only use the LinkedHashSet preferentially when you need elements to remain in insertion order.
• ConcurrentSkipListSet keeps it's elements in sorted order and is thread-safe and usually preferable to a synchronized wrapped set.
• With CopyOnWriteArraySet all operations that change the contents of a CopyOnWriteArraySet collection cause the underlying array to be replaced with a copy of itself before the contents of the array are changed. Any active iterators will continue to see the unmodified array, so there is no need for locks.
• PriorityQueue add and remove methods take time that is proportionate to the number of objects in the queue. Queues based on the PriorityQueue class do not block. PriorityBlockingQueue is similar in performance but does block.
• DelayQueue is a specialized blocking queue that consults the objects it contains as to when they can be removed from the queue.
• A SynchronousQueue object is always empty; the put method blocks unless another thread is waiting for the object's take method to return.
• If you are not interested in how objects will be organized in a collection, then the only other consideration is performance. In that case, use the ArrayList class. It is fast and makes efficient use of memory.
By - Amaresh
Please find more topics under JASe Archive!!!
Friday, July 17, 2009
WHAT'S NEW IN JAVA
DOJO
Dojo Toolkit is an open source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross platform for JavaScript/Ajax based applications and web sites.
Dojo is an Open Source DHTML toolkit written in JavaScript, it will support Cross-platforms present stable Dojo release is 1.3.2.
Dojo Base includes Ajax, events, packaging, CSS-based querying, animations, JSON, language utilities and that's just the beginning. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.
Dojo allows you to easily build dynamic capabilities into web pages and any other environment that supports JavaScript sanely. You can use the components that Dojo provides to make your web sites more usable, responsive, and functional. With Dojo you can build degradable user interfaces more easily, prototype interactive widgets quickly, and animate transitions. You can use the lower-level APIs and compatibility layers from Dojo to write portable JavaScript and simplify complex scripts. Dojo's event system, I/O APIs, and generic language enhancement form the basis of a powerful programming environment. You can use the Dojo build tools to write command-line unit-tests for your JavaScript code. The Dojo build process helps you optimize your JavaScript for deployment by grouping sets of files together and reuse those groups through "profiles".
Dojo does all of these things by layering capabilities onto a very small core which provides the package system and little else. When you write scripts with Dojo, you can include as little or as much of the available APIs as you need to suit your needs. Dojo provides multiple points of entry, interpreter independence, forward looking APIs, and focuses on reducing barriers to adoption.
Dojo Features
Asynchronous communication,
Packaging system,
Client-side data storage,
Server-side data storage,
Support for Adobe Integrated Runtime (AIR).
For More information please click
Announcements
James Gosling: on the Java Road
This is update regarding on 2009 JVM Language Summit to be held at Sun's Santa Clara campus on September 16-18, 2009. More information is available at http://jvmlangsummit.com.
The JVM Language Summit is an open technical collaboration among language designers, compiler writers, tool builders, runtime engineers, and VM architects. We will share our experiences as creators of programming languages for the JVM and of the JVM itself.
By - Ramesh
Dojo Toolkit is an open source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross platform for JavaScript/Ajax based applications and web sites.
Dojo is an Open Source DHTML toolkit written in JavaScript, it will support Cross-platforms present stable Dojo release is 1.3.2.
Dojo Base includes Ajax, events, packaging, CSS-based querying, animations, JSON, language utilities and that's just the beginning. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.
Dojo allows you to easily build dynamic capabilities into web pages and any other environment that supports JavaScript sanely. You can use the components that Dojo provides to make your web sites more usable, responsive, and functional. With Dojo you can build degradable user interfaces more easily, prototype interactive widgets quickly, and animate transitions. You can use the lower-level APIs and compatibility layers from Dojo to write portable JavaScript and simplify complex scripts. Dojo's event system, I/O APIs, and generic language enhancement form the basis of a powerful programming environment. You can use the Dojo build tools to write command-line unit-tests for your JavaScript code. The Dojo build process helps you optimize your JavaScript for deployment by grouping sets of files together and reuse those groups through "profiles".
Dojo does all of these things by layering capabilities onto a very small core which provides the package system and little else. When you write scripts with Dojo, you can include as little or as much of the available APIs as you need to suit your needs. Dojo provides multiple points of entry, interpreter independence, forward looking APIs, and focuses on reducing barriers to adoption.
Dojo Features
Asynchronous communication,
Packaging system,
Client-side data storage,
Server-side data storage,
Support for Adobe Integrated Runtime (AIR).
For More information please click
Announcements
James Gosling: on the Java Road
This is update regarding on 2009 JVM Language Summit to be held at Sun's Santa Clara campus on September 16-18, 2009. More information is available at http://jvmlangsummit.com.
The JVM Language Summit is an open technical collaboration among language designers, compiler writers, tool builders, runtime engineers, and VM architects. We will share our experiences as creators of programming languages for the JVM and of the JVM itself.
By - Ramesh
PRODUCT AND TECHNOLOGY RELEASES
Oracle Database 11g
New for Java, JDBC, .NET, PHP, and OCI
For JDBC developers, new features include: JDBC 4.0, Advanced security in JDBC-Thin (Kerberos, Radius), Database Change Notification, better RAC support; performance, diagnosability and manageability.
For Java in the Database a new JIT compiler automatically compiles Java code, new ease-of-use features including a JDK-Like interface, database resident jars, output redirect, property management interface, and utilities.
For .NET developers: new data access features with Oracle Database 11g, including abstract/user-defined data types, ASP.NET providers, and client-side HA features for Oracle grids; new enhancements to the Visual Studio tools: full integration into Visual Studio 2005, source control, and database script management.
For PHP, a new database resident connection pool allows multiple Oracle clients to share a server-side pool of connections, providing application scalability.
OCI improves database scalability and application performance with client query result cache.
Development - Connectivity (e.g. JDBC, ODBC, Wireless) ,Performance Tuning, Security, Design, Programming (e.g. Java/J2EE, JSP, Beans, XML, .NET, BPEL, ADF, AJAX, SQL, PL/SQL, OC4J), 11g Upcoming Features.
Exposure to JDBC, Oracle JDBC, Java in the Oracle database, .NET of the Oracle Database, PHP, and OCI.
Support for new Java/JDBC standards, security and performance enhancements.
New .NET data access features: UDT, ASP.NET providers, client-side HA for Oracle Grids, .NET tools.
Database resident connection pool for PHP and OCI, query result set cache across sessions/threads.
By - Ramesh
New for Java, JDBC, .NET, PHP, and OCI
For JDBC developers, new features include: JDBC 4.0, Advanced security in JDBC-Thin (Kerberos, Radius), Database Change Notification, better RAC support; performance, diagnosability and manageability.
For Java in the Database a new JIT compiler automatically compiles Java code, new ease-of-use features including a JDK-Like interface, database resident jars, output redirect, property management interface, and utilities.
For .NET developers: new data access features with Oracle Database 11g, including abstract/user-defined data types, ASP.NET providers, and client-side HA features for Oracle grids; new enhancements to the Visual Studio tools: full integration into Visual Studio 2005, source control, and database script management.
For PHP, a new database resident connection pool allows multiple Oracle clients to share a server-side pool of connections, providing application scalability.
OCI improves database scalability and application performance with client query result cache.
Development - Connectivity (e.g. JDBC, ODBC, Wireless) ,Performance Tuning, Security, Design, Programming (e.g. Java/J2EE, JSP, Beans, XML, .NET, BPEL, ADF, AJAX, SQL, PL/SQL, OC4J), 11g Upcoming Features.
Exposure to JDBC, Oracle JDBC, Java in the Oracle database, .NET of the Oracle Database, PHP, and OCI.
Support for new Java/JDBC standards, security and performance enhancements.
New .NET data access features: UDT, ASP.NET providers, client-side HA for Oracle Grids, .NET tools.
Database resident connection pool for PHP and OCI, query result set cache across sessions/threads.
By - Ramesh
TIPS AND TRICKS
Using Enhanced For-Loops with Your Classes
The enhanced for-loop is a popular feature introduced with the Java SE platform in version 5.0. Its simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.
Because the old style of coding didn't become invalid with the new for-loop syntax, you don't have to use an enhanced for-loop when visiting each element of an array/collection. However, with the new style, one's code would typically change from something like the following:
for (int i=0; i<=array.length; i++) {
System.out.println("Element: " + array[i]);
}
To the newer form:
for (String element : array) {
System.out.println("Element: " + element);
}
Assuming "array" is defined to be an array of String objects, each element is assigned to the element variable as it loops through the array.
These basics of the enhanced for-loop were covered in an earlier Tech Tip: The Enhanced For Loop
By - Ramesh
The enhanced for-loop is a popular feature introduced with the Java SE platform in version 5.0. Its simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.
Because the old style of coding didn't become invalid with the new for-loop syntax, you don't have to use an enhanced for-loop when visiting each element of an array/collection. However, with the new style, one's code would typically change from something like the following:
for (int i=0; i<=array.length; i++) {
System.out.println("Element: " + array[i]);
}
To the newer form:
for (String element : array) {
System.out.println("Element: " + element);
}
Assuming "array" is defined to be an array of String objects, each element is assigned to the element variable as it loops through the array.
These basics of the enhanced for-loop were covered in an earlier Tech Tip: The Enhanced For Loop
By - Ramesh
CASE STUDIES
ABOUT STRING POOL
Creating a String
There are two ways to create a String object in Java:
Using the new operator. For example,
String str = new String("Hello");.
Using a string literal or constant expression). For example,
String str="Hello"; (string literal) or
String str="Hel" + "lo"; (string constant expression). – In lining the statement at compile time.
What is difference between these String's creations? In Java, the equals method can be considered to perform a deep comparison of the value of an object, whereas the == operator performs a shallow comparison. The equals method compares the content of two objects rather than two objects' references. The == operator with reference types (i.e., Objects) evaluates as true if the references are identical - point to the same object. With value types (i.e., primitives) it evaluates as true if the value is identical.
The equals method is to return true if two objects have identical content - however, the equals method in the java.lang.Object class - the default equals method if a class does not override it - returns true only if both references point to the same object.
Let's use the following example to see what difference between these creations of string:
public class StringCreationExample {
public static void main (String args[]) {
String str1 = "Hello";
String str2 = "Hello";
System.out.println("str1 and str2 are created by using string literal.");
System.out.println(" str1 == str2 is " + (str1 == str2));
System.out.println(" str1.equals(str2) is " + str1.equals(str2));
String str3 = new String("Hello");
String str4 = new String("Hello");
System.out.println("str3 and str4 are created by using new operator.");
System.out.println(" str3 == str4 is " + (str3 == str4));
System.out.println(" str3.equals(str4) is " + str3.equals(str4));
String str5 = "Hel"+ "lo";
String str6 = "He" + "llo";
System.out.println("str5 and str6 are created by using string
constant expression.");
System.out.println(" str5 == str6 is " + (str5 == str6));
System.out.println(" str5.equals(str6) is " + str5.equals(str6));
String s = "lo";
String str7 = "Hel"+ s;
String str8 = "He" + "llo";
System.out.println("str7 is computed at runtime.");
System.out.println("str8 is created by using string constant
expression.");
System.out.println(" str7 == str8 is " + (str7 == str8));
System.out.println(" str7.equals(str8) is " + str7.equals(str8));
}
}
The output result is:
str1 and str2 are created by using string literal.
str1 == str2 is true
str1.equals(str2) is true
str3 and str4 are created by using new operator.
str3 == str4 is false
str3.equals(str4) is true
str5 and str6 are created by using string constant expression.
str5 == str6 is true
str5.equals(str6) is true
str7 is computed at runtime.
str8 is created by using string constant expression.
str7 == str8 is false
str7.equals(str8) is true
The creation of two strings with the same sequence of letters without the use of the new keyword will create pointers to the same String in the Java String literal pool. The String literal pool is a way Java conserves resources.
String Literal Pool
String allocation, like all object allocation, proves costly in both time and memory. The JVM performs some trickery while instantiating string literals to increase performance and decrease memory overhead. To cut down the number of String objects created in the JVM, the String class keeps a pool of strings. Each time your code creates a string literal, the JVM checks the string literal pool first. If the string already exists in the pool, a reference to the pooled instance returns, it uses Flyweight design pattern. If the string does not exist in the pool, a new String object instantiates then is placed in the pool. Java can make this optimization since strings are immutable and can be shared without fear of data corruption.
For example:
public class Program
{
public static void main(String[] args)
{
String str1 = "Hello";
String str2 = "Hello";
System.out.printlntr1 == str2);
}
}
The result is:
true
Unfortunately, when you use
String a=new String("Hello");
a String object is created out of the String literal pool, even if an equal string already exists in the pool. Considering all that, avoid new String unless you specifically know that you need it!
For example:
public class Program
{
public static void main(String[] args)
{
String str1 = "Hello";
String str2 = new String("Hello");
System.out.print(str1 == str2 + " ");
System.out.print(str1.equals(str2));
}
}
The result is:
false true
A JVM has a string pool where it keeps at most one object of any String. String literals always refer to an object in the string pool. String objects created with the new operator do not refer to objects in the string pool but can be made to using String's intern() method. The java.lang.String.intern() returns an interned String, that is, one that has an entry in the global String pool. If the String is not already in the global String pool, then it will be added.
For example:
public class Program
{
public static void main(String[] args)
{
// Create three strings in three different ways.
String s1 = "Hello";
String s2 = new StringBuffer("He").append("llo").toString();
String s3 = s2.intern();
// Determine which strings are equivalent using the ==
// operator
System.out.println("s1 == s2? " + (s1 == s2));
System.out.println("s1 == s3? " + (s1 == s3));
}
}
The output is:
s1 == s2? false
s1 == s3? True
There is a table always maintaining a single reference to each unique String object in the global string literal pool ever created by an instance of the runtime in order to optimize space. That means that they always have a reference to String objects in string literal pool, therefore, the string objects in the string literal pool not eligible for garbage collection.
String Literals in the Java Language Specification Third Edition
Each string literal is a reference to an instance of class String. String objects have a constant value. It is not editable.
Thus, the test program consisting of the compilation unit:
package testPackage;
class StringTest {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
and the compilation unit:
package other;
public class Other { static String hello = "Hello"; }
Produces the output:
true true true true false true
This example illustrates six points:
Literal strings within the same class in the same package represent references to the same String object.
Literal strings within different classes in the same package represent references to the same String object.
Literal strings within different classes in different packages likewise represent references to the same String object.
Strings computed by constant expressions are computed at compile time and then treated as if they were literals.
Strings computed by concatenation at run time are newly created and therefore distinct.
The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
By - Senthil
Creating a String
There are two ways to create a String object in Java:
Using the new operator. For example,
String str = new String("Hello");.
Using a string literal or constant expression). For example,
String str="Hello"; (string literal) or
String str="Hel" + "lo"; (string constant expression). – In lining the statement at compile time.
What is difference between these String's creations? In Java, the equals method can be considered to perform a deep comparison of the value of an object, whereas the == operator performs a shallow comparison. The equals method compares the content of two objects rather than two objects' references. The == operator with reference types (i.e., Objects) evaluates as true if the references are identical - point to the same object. With value types (i.e., primitives) it evaluates as true if the value is identical.
The equals method is to return true if two objects have identical content - however, the equals method in the java.lang.Object class - the default equals method if a class does not override it - returns true only if both references point to the same object.
Let's use the following example to see what difference between these creations of string:
public class StringCreationExample {
public static void main (String args[]) {
String str1 = "Hello";
String str2 = "Hello";
System.out.println("str1 and str2 are created by using string literal.");
System.out.println(" str1 == str2 is " + (str1 == str2));
System.out.println(" str1.equals(str2) is " + str1.equals(str2));
String str3 = new String("Hello");
String str4 = new String("Hello");
System.out.println("str3 and str4 are created by using new operator.");
System.out.println(" str3 == str4 is " + (str3 == str4));
System.out.println(" str3.equals(str4) is " + str3.equals(str4));
String str5 = "Hel"+ "lo";
String str6 = "He" + "llo";
System.out.println("str5 and str6 are created by using string
constant expression.");
System.out.println(" str5 == str6 is " + (str5 == str6));
System.out.println(" str5.equals(str6) is " + str5.equals(str6));
String s = "lo";
String str7 = "Hel"+ s;
String str8 = "He" + "llo";
System.out.println("str7 is computed at runtime.");
System.out.println("str8 is created by using string constant
expression.");
System.out.println(" str7 == str8 is " + (str7 == str8));
System.out.println(" str7.equals(str8) is " + str7.equals(str8));
}
}
The output result is:
str1 and str2 are created by using string literal.
str1 == str2 is true
str1.equals(str2) is true
str3 and str4 are created by using new operator.
str3 == str4 is false
str3.equals(str4) is true
str5 and str6 are created by using string constant expression.
str5 == str6 is true
str5.equals(str6) is true
str7 is computed at runtime.
str8 is created by using string constant expression.
str7 == str8 is false
str7.equals(str8) is true
The creation of two strings with the same sequence of letters without the use of the new keyword will create pointers to the same String in the Java String literal pool. The String literal pool is a way Java conserves resources.
String Literal Pool
String allocation, like all object allocation, proves costly in both time and memory. The JVM performs some trickery while instantiating string literals to increase performance and decrease memory overhead. To cut down the number of String objects created in the JVM, the String class keeps a pool of strings. Each time your code creates a string literal, the JVM checks the string literal pool first. If the string already exists in the pool, a reference to the pooled instance returns, it uses Flyweight design pattern. If the string does not exist in the pool, a new String object instantiates then is placed in the pool. Java can make this optimization since strings are immutable and can be shared without fear of data corruption.
For example:
public class Program
{
public static void main(String[] args)
{
String str1 = "Hello";
String str2 = "Hello";
System.out.printlntr1 == str2);
}
}
The result is:
true
Unfortunately, when you use
String a=new String("Hello");
a String object is created out of the String literal pool, even if an equal string already exists in the pool. Considering all that, avoid new String unless you specifically know that you need it!
For example:
public class Program
{
public static void main(String[] args)
{
String str1 = "Hello";
String str2 = new String("Hello");
System.out.print(str1 == str2 + " ");
System.out.print(str1.equals(str2));
}
}
The result is:
false true
A JVM has a string pool where it keeps at most one object of any String. String literals always refer to an object in the string pool. String objects created with the new operator do not refer to objects in the string pool but can be made to using String's intern() method. The java.lang.String.intern() returns an interned String, that is, one that has an entry in the global String pool. If the String is not already in the global String pool, then it will be added.
For example:
public class Program
{
public static void main(String[] args)
{
// Create three strings in three different ways.
String s1 = "Hello";
String s2 = new StringBuffer("He").append("llo").toString();
String s3 = s2.intern();
// Determine which strings are equivalent using the ==
// operator
System.out.println("s1 == s2? " + (s1 == s2));
System.out.println("s1 == s3? " + (s1 == s3));
}
}
The output is:
s1 == s2? false
s1 == s3? True
There is a table always maintaining a single reference to each unique String object in the global string literal pool ever created by an instance of the runtime in order to optimize space. That means that they always have a reference to String objects in string literal pool, therefore, the string objects in the string literal pool not eligible for garbage collection.
String Literals in the Java Language Specification Third Edition
Each string literal is a reference to an instance of class String. String objects have a constant value. It is not editable.
Thus, the test program consisting of the compilation unit:
package testPackage;
class StringTest {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
and the compilation unit:
package other;
public class Other { static String hello = "Hello"; }
Produces the output:
true true true true false true
This example illustrates six points:
Literal strings within the same class in the same package represent references to the same String object.
Literal strings within different classes in the same package represent references to the same String object.
Literal strings within different classes in different packages likewise represent references to the same String object.
Strings computed by constant expressions are computed at compile time and then treated as if they were literals.
Strings computed by concatenation at run time are newly created and therefore distinct.
The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
By - Senthil
Subscribe to:
Posts (Atom)