Tip « Development « Java Articles

Home
Java Articles
1.Build Deploy
2.Class
3.Core Library
4.Data Types
5.Database JDBC
6.Design
7.Development
8.File Input Output
9.Graphics Desktop
10.J2EE Enterprise
11.J2ME Wireless
12.JVM
13.Language
14.Library Product
15.Network
16.Security
17.SOA Web Services
18.Test
19.Web Development
20.XML
Java Articles » Development » Tip 

1. Java Tip 124: Trace your steps in Java 1.4    javaworld.com

I firmly believe the runtime system should provide enough metadata about the system itself so programs can make better decisions and complete tasks. Java has been able to introspect and reflect on classes for some time, but until now it has lacked the simple ability to map runtime code back to its position in the source code file. The pre-Java 1.4 solution was to manually parse an exception's stack trace. Now, with Java 1.4, we have a better solution.

2. Java Tip 139: Ask the right questions in your survey application    javaworld.com

If we use a survey design where an answer to a question does not determine the next question, then Turbo Tax users who are single or married but not filing jointly would be quite frustrated. Additionally, when new laws and regulations cause the logic and data to change from year to year, Turbo Tax code would have to be modified. It would be more cost effective if such logic and data was independent and maintained separately from the codebase. This article shows you how to develop an application that decouples the surveying content and logic from the application.

3. Java Tip 61: Cut, copy, and paste in Java    javaworld.com

Java offers two types of clipboards: local and system. Local clipboards are only available inside the virtual machine that your applet or application is running. However, unlike some operating systems that limit you to only one clipboard, Java allows you to have as many local clipboards as you desire. Accessing a particular local clipboard is as easy as referring to it by name.

4. Java Tip 116: Set your table options -- at runtime!    javaworld.com

In the following sections, we'll work with various JTable display options -- such as scroll bars, column widths, selection, and other attributes. We'll extend MyTable and incorporate various methods that will support the display features we want to change. Each section adds a new method to the MyTable class, so in the end, we'll have a totally reusable JTable.

5. Java Tip 67: Lazy instantiation    javaworld.com

One of the memory conservation techniques Java programmers find useful is lazy instantiation. With lazy instantiation, a program refrains from creating certain resources until the resource is first needed -- freeing valuable memory space. In this tip, we examine lazy instantiation techniques in Java class loading and object creation, and the special considerations required for Singleton patterns. The material in this tip derives from the work in Chapter 9 of our book, Java in Practice: Design Styles & Idioms for Effective Java (see Resources).

6. Java Tip 130: Do you know your data size?    javaworld.com

Since Java purposefully hides many aspects of memory management, discovering how much memory your objects consume takes some work. You could use the Runtime.freeMemory() method to measure heap size differences before and after several objects have been allocated. Several articles, such as Ramchander Varadarajan's "Question of the Week No. 107" (Sun Microsystems, September 2000) and Tony Sintes's "Memory Matters" (JavaWorld, December 2001), detail that idea. Unfortunately, the former article's solution fails because the implementation employs a wrong Runtime method, while the latter article's solution has its own imperfections:

7. Java Tip 141: Fast math with JNI    javaworld.com

Since my trusty C++ compiler produced fast math code, I just needed to call these math routines instead of the slow StrictMath routines from my Java program. Java Native Interface (JNI) enables Java code to interface with native code written in other languages like C/C++. It enables you to write the bulk of your application in Java and still utilize highly optimized native code where necessary. And in the corporate computing world, JNI enables Java applications to connect to legacy code that might be difficult or impractical to port to Java.

8. Java Tip 71: Use dynamic messaging in Java    javaworld.com

This Java Tip shows you how to use the Reflection API, and specifically how to use it to implement a simple system for sending dynamic messages. In our particular case, this simple system is the doesNotUnderstand message.

9. Java Tip 135: Layer and compare property files    javaworld.com

With the PropDiff utility described here, not only can variants of large property files be compared with ease, but also the layering of property files can be used as an organizing principle that makes the early stages of implementation much smoother.

10. Java Tip 82: Build data-type-independent JDBC applications    javaworld.com

As the number of tables that need to be populated increases, you'll need to write more code. But even this is only the case for a single database. If the data is ported to a different database system, you must rewrite all the existing code to account for the different data types in the new database. The issue of cross-database data typing has earned well-deserved notoriety in database programming.

11. Java Tip 10: Implement callback routines in Java    javaworld.com

Java's support of interfaces provides a mechanism by which we can get the equivalent of callbacks. The trick is to define a simple interface that declares the method we wish to be invoked.

12. Java Tip 136: Protect Web application control flow    javaworld.com

For a server-based solution, the Synchronizer Token pattern (from Core J2EE Patterns) can be applied, which requires minimal contribution from the client side. The basic idea is to set a token in a session variable before returning a transactional page to the client. This page carries the token inside a hidden field. Upon submission, request processing first tests for the presence of a valid token in the request parameter by comparing it with the one registered in the session. If the token is valid, processing can continue normally, otherwise an alternate course of action is taken. After testing, the token resets to null to prevent subsequent submissions until a new token is saved in the session, which must be done at the appropriate time based on the desired application flow of control. In other words, the one-time privilege to submit data is given to one specific instance of a view. This Synchronizer Token pattern is used in the Apache Jakarta Project's Struts framework, the popular open source Model-View-Controller implementation.

13. XForms tip: Accepting XForms data in Java    ibm.com

Notice that nothing strange has been done with the data shown in Listing 2. There are no strange encoding schemes, and the destination, or action, is a simple Java? servlet. A form submitted in this way simply sends the XML instance document as the contents of a POST request.

14. Tip: Use Tiles Decorations; Reduce Configuration    developer.com

The TilesDecorationFilter provides auto-configuration of tiles definitions. To use it, simply configure your filter to intercept any request to which you?d like to provide a standard look and feel. The filter will intercept the request, create a new templating definition that includes the standard set of tiles, configure the content page dynamically based on the original request, and render the definition. In many cases, the use of the decoration filter reduces the amount of XML configuration from one tiles definition per unique request to a single definition. This single definition then is applied to all requests.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.