Function-Oriented Java

Contents

Introduction
Chapter 1. Files
Chapter 2. Zips
Chapter 3. Regular Expressions
Chapter 4. NIO File Functions
Chapter 5. Directory
Chapter 6. Date and Calendar
Chapter 7. Http and Sockets
Chapter 8. Swing GUIs
Chapter 9. Stream
Chapter 10.String functions
Chapter 11. XML
Chapter 12. Security
Chapter 13. Database
Chapter 14. Arrays and Collections
Chapter 15. Applet
Chapter 16. Math
Chapter 17. Financial
Chapter 18. Object Introspection
Chapter 19. Object Management


Download source









Introduction

Java is a remarkable language. It exhibits capabilities that you will not see in other progamming languages -- particularly in its portability, its simplicity and its power.

Like many computer languages,however, it treads a fine line between high-level capability that provides little flexibility on the one hand and, one the other, a flexibility that requires careful attention to each feature point. To name a famous example -- on the negative side-- Java requires about a dozen lines of code to open a File for read-only access while languages like Python let you do it in one line. Still, Java offers great control of how you access that file: you can treat is as a sequential stream that you buffer in memory and serve up piecemeal to a calling routine; likewise, in the java.nio package, there is some capability for blazing file I/O.

For the Java programmer who is trying to be productive and efficient, this is a two-edged sword. The fine control of resources permits a more robust application. But whether you are a seasoned professional or a Cobol or Visual Basic programmer wishing to move the world of object orientation, Java can be frustating at times.

If you are trying to write something quickly, like a proof-of-concept or a utility, the fine control really gets in your way. At a certain level,it tends to interfere with creativity. You are trying to write a Swing editor and you need to save a file. It's a relatively straightforward process - a dozen lines of code you may have written a dozen times in the past. Yet, it requires that you stop the creative flow and research -- again!! -- how the java.io package works. Frequently, you resort to a Google search, which may or may not reveal the 12 lines.

You can see right away why many Java developers migrate to Python/Jython and Ruby in the evening hours.

This gets to the point of this book. That dozen lines of code is something that many Java developers store in their personal bag of tricks. Or they have the section dog-eared in their favorite reference.

This book wants to become that reference. Whether the programmer needs to do a quick cut-and-paste or to utilize the functions from within the Function Oriented Java distribution jars, the idea is to provide simple, direct services to the most common Java routines. All available from one line of code. Ready to go without having to do any research.

When research is necessary, we provide helpful text explaining what's going on under the covers. Otfen, a simple one-line call will provide a service, but it may not be quite the service you need. Generally, most high-level languages can make you highly productive... when they work. We explain why exactly the function may or may not fit the bill. And, if you want to tweak the code, it's there, it's Java....

How the code is structured

As much as possible, we built the code to fit the model of the public static method, which requires no object instantiation. In Java, you see this in methods like String.valueOf() or Long.parseLong() which provide quick returns without allocating memory for new objects.

Of course, this approach doesn't always fit the bill. Although it is brief and probably very evident to a Cobol programmer, it doesn't always work to provide the service that you require. So we haven't been religious about using static Functions, despite the name of the book. Where a function is the service you require, we provide a function. Where object instantion works best, we whip out the "new" keyword and allocate a new object. What we do guarantee is that we are provide a high-level functionality that will save you some typing.

The drill...

Each function provided within Function-Oriented Java is described in the appropiate chapter. We break it down into these areas

  • a how description of the function
  • how to call the function from within your code
  • the function itself is listed
  • a description of what is going on in the code and various considerations about it.
  • various sidebars in gray text will provide thoughts on how you should approach all functions. For example, in the File functions chapter, we throw IOExceptions from every method. If you are a seasoned pro, this is pretty boring stuff, but if you are new to Java, you might want to wade through these.


    Copyright (c)2004 Gervase Gallant gervasegallant@yahoo.com