Java, J2ME and Struts
Java
Java has gained enormous popularity since it first appeared. Its rapid ascension and wide acceptance can be traced to its design and programming features, particularly in its promise that you can write a program once, and run it anywhere. Java was chosen as the programming language for network computers (NC) and has been perceived as a universal front end for the enterprise database. As stated in Java language white paper by Sun Microsystems: “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, multithreaded, and dynamic.”
Java™ has significant advantages over other languages and environments that make it suitable for just about any programming task.
The advantages of Java are as follows:
• Java is easy to learn.
Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.
• Java is object-oriented.
This allows you to create modular programs and reusable code.
• Java is platform-independent.
One of the most significant advantages of Java is its ability to move easily from one computer system to another. The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels.
• Java is distributed.
Java is designed to make distributed computing easy with the networking capability that is inherently integrated into it. Writing network programs in Java is like sending and receiving data to and from a file.
• Java is secure.
Java considers security as part of its design. The Java language, compiler, interpreter, and runtime environment were each developed with security in mind.
• Java is robust.
Robust means reliability. Java puts a lot of emphasis on early checking for possible errors, as Java compilers are able to detect many problems that would first show up during execution time in other languages.
• Java is multithreaded.
Multithreaded is the capability for a program to perform several tasks simultaneously within a program. In Java, multithreaded programming has been smoothly integrated into it, while in other languages, operating system-specific procedures have to be called in order to enable multithreading.
Because of Java’s robustness, ease of use, cross-platform capabilities and security features, it has become a language of choice for providing worldwide Internet solutions.
J2ME
Palmtops, Pagers and cell phones are everywhere and the variety is endless. The industry’s need for these devices to be able to run and perform almost any task that used to be done on desktops requires a standard and simple way to develop applications. The solution must suit a variety of platforms and take in care many limitations such as limited memory, small screen sizes, alternative input methods, and slow processors that being small brings with.
Recognizing that “one size doesn’t fit all”, Sun regrouped its Java technologies into three editions, each is aimed at a specific market segment:
• J2EE - Aimed at heavy duty server systems.
• J2SE - Aimed at Standard desktop & workstation applications
And Java 2 Platform Micro Edition (J2ME) - Aimed at Small & memory constrained devices and standardize the use of Java technology in wireless devices. The J2ME architecture had to be modular and scalable due to the diversity of target devices. To achieve this, J2ME provides a range of virtual machines, each optimized to the different processor types and memory footprints.
J2ME advantages include improved security and consistency of applications across platforms and devices, superior user interfaces with graphics, the ability to function off-line out of wireless coverage, peer-to-peer networking and no licensing expenses needed for the SDK, which means that anyone can create an application and market it.
J2ME vs. WAP
J2ME apps have much more to offer than those built under the Wireless Application Protocol (WAP), in terms of both features and security. Whereas WAP is a thin-client development protocol, J2ME is a development platform specifically for smart applications. J2ME applications offer the following security advantages over WAP applications:
• Without a WAP gateway in the middle, smart applications can provide scalable end-to-end security from the back end to wireless devices. This will become especially important as the back end evolves into a message-driven Web-services framework.
• Smart applications can store and process data locally, thereby reducing network traffic. Not only does this conserve precious wireless bandwidth and reduce latency, it reduces the likelihood that crucial information will be intercepted or interrupted (e.g., by denial-of-service attacks).
• Smart applications utilize device processing power efficiently. Instead of encrypting everything with the same key strength regardless of needs, rich clients can establish a comprehensive differentiating security policy based on the content.
J2ME vs. native platforms
As compared with the native platforms, the main strength of the Java platform is that it allows us to write portable applications. The Java platform’s portability stems from its execution model. Specifically, it stems from the use of the JVM to process Java bytecode into machine code at runtime, providing a compatibility layer on top of the hardware. The Java platform’s execution model also introduces some important security benefits that are lacking in device-native applications. These benefits are as follows:
• The JVM verifies all classes in class loaders and ensures that applications do not perform any dangerous operations. Because runtime class verification is computationally expensive for MIDP VMs, MIDP has a special two-step bytecode verification scheme. We’ll address this scheme in a later section.
• The JVM has a monitoring mechanism to safeguard runtime application errors. A good example is the garbage collector. The JVM can clean up application memory heaps automatically at runtime. This helps to avoid memory leaks, which are the major cause of crashes among native applications.
• The JVM can provide a security manager or sandbox for applications. Viruses and other hostile code accidentally downloaded from the Web can pose serious security risks. On the Java platform, entire applications (i.e., JAR files) can be digitally signed. The JVM security manager grants the signed application privileges to access specific APIs (domains) based on the trust level of the signer. We’ll discuss domain-based mobile code security in more detail in a later section.
Smart, usability-focused design and the Java platform’s built-in execution model give J2ME applications significant performance and security advantages over both WAP and native applications.
Struts
Struts is an application development framework that is designed for and used with the popular J2EE (Java 2, Enterprise Edition) platform. It cuts time out of the development process and makes developers more productive by providing them a series of tools and components to build applications with. It is non-proprietary and works with virtually any J2EE-compliant application server. Struts falls under the Jakarta subproject of the Apache Software Foundation and comes with an Open Source license (meaning it has no cost and its users have free access to all its internal source code).
In addition to helping you work faster and having no cost, Struts also helps make your end work products better.
There are several different ways of looking at Struts. The three main ways are that Struts is:
• An MVC Framework
Struts provide a unified framework for deploying servlet and JSP applications that use the MVC architecture.
• A Collection of Utilities
Struts provides utility classes to handle many of the most common tasks in Web application development
• A Set of JSP Custom Tag Libraries
Struts provides custom tag libraries for outputting bean properties, generating HTML forms, iterating over various types of data structures, and conditionally outputting HTML.
Advantages of Struts
You can easily implement the MVC approach by using RequestDispatcher.forward in your servlets and jsp:getProperty or the JSP 2.0 expression language in your JSP pages. However, Struts offers a number of significant advantages over these techniques alone. Here is a summary:
• Centralized File-Based Configuration
Rather than hard-coding information into Java programs, many Struts values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout.
• Form Beans
In JSP, you can use property=”*” with jsp:setProperty to automatically populate a JavaBean component based on incoming request parameters. Unfortunately, however, in the standard API this capability is unavailable to servlets, even though with MVC it is really servlets, not JSP pages, that should usually be the target of form submissions. Apache Struts extends this capability to Java code and adds in several useful utilities, all of which serve to greatly simplify the processing of request parameters.
• Bean Tags
Apache Struts provides a set of custom JSP tags (bean:write, in particular) that let you easily output the properties of JavaBeans components. Basically, these are concise and powerful variations of the standard jsp:useBean and jsp:getProperty tags.
• HTML Tags
Apache Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes:
o It lets you get initial form-field values from Java objects.
o It lets you redisplay forms with some or all previously entered values intact.
• Form Field Validation
Apache Struts has built-in capabilities for checking that form values are in the required format. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained.
This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript).
• Consistent Approach.
Struts encourage consistent use of MVC throughout your application.
July 26th, 2008 at 2:00 pm
Hi, I was looking around for a while searching for web services white papers and I happened upon this site and your post regarding Java, J2ME and Struts, I will definitely this to my web services white papers bookmarks!