Java Tutorials
201. concat(), replace(), and trim() Strings in Java
By: Ivan Lim : 2007-09-12
Description: You can concatenate two strings using concat(), shown here. The replace() method replaces all occurrences of one character in the invoking string with another character. The trim() method is quite useful when you process user commands. For example, the following program prompts the user for the name of a state and then displays that state's capital. It uses trim() to remove any leading or trailing whitespace that may have inadvertently been entered by the user.
202. valueOf() and toString() in Java
By: Henry : 2007-09-12
Description: When Java converts data into its string representation during concatenation, it does so by calling one of the overloaded versions of the string conversion method valueOf() defined by String. valueOf() is overloaded for all the simple types and for type Object. For the simple types, valueOf() returns a string that contains the human-readable equivalent of the value with which it is called. For objects, valueOf() calls the toString() method on the object. We will look more closely at valueOf() later in this chapter. Here, let's examine the toString() method, because it is the means by which you can determine the string representation for objects of classes that you create.
203. String Concatenation in Java
By: Emiley J : 2007-09-12
Description: In general, Java does not allow operators to be applied to String objects. The one exception to this rule is the + operator, which concatenates two strings, producing a String object as the result. This allows you to chain together a series of + operations. For example, the following fragment concatenates three strings:
204. String Class Constructors in Java
By: Daniel Malcolm : 2007-09-12
Description: The String class supports several constructors. To create an empty String, you call the default constructor. For example,
205. Disadvantages of using Native methods in Java
By: Charles : 2007-09-12
Description: Native methods seem to offer great promise, because they enable you to gain access to your existing base of library routines, and they offer the possibility of faster run-time execution. But native methods also introduce two significant problems:
206. Sample using loadLibrary() to call Native methods in Java
By: Charles : 2007-09-12
Description: Although it is rare, occasionally, you may want to call a subroutine that is written in a language other than Java. Typically, such a subroutine exists as executable code for the CPU and environment in which you are working—that is, native code. For example, you may want to call a native code subroutine to achieve faster execution time. Or, you may want to use a specialized, third-party library, such as a statistical package. However, because Java programs are compiled to bytecode, which is then interpreted (or compiled on-the-fly) by the Java run-time system, it would seem impossible to call a native code subroutine from within your Java program. Fortunately, this conclusion is false. Java provides the native keyword, which is used to declare native code methods. Once declared, these methods can be called from inside your Java program just as you call any other Java method.
207. strictfp in Java 2
By: Baski : 2007-09-12
Description: Java 2 adds a new keyword to the Java language, called strictfp. With the creation of Java 2, the floating point computation model was relaxed slightly to make certain floating point computations faster for certain processors, such as the Pentium. Specifically, the new model does not require the truncation of certain intermediate values that occur during a computation. By modifying a class or a method with strictfp, you ensure that floating point calculations (and thus all truncations) take place precisely as they did in earlier versions of Java. The truncation affects only the exponent of certain operations. When a class is modified by strictfp, all the methods in the class are also modified by strictfp automatically.
208. Reading from a file and writing to a file using Java program
By: Baski : 2007-09-10
Description: Java provides a number of classes and methods that allow you to read and write files. In Java, all files are byte-oriented, and Java provides methods to read and write bytes from and to a file. However, Java allows you to wrap a byte-oriented file stream within a character-based object. This tutorial examines the basics of file I/O.
209. Error applying transforms. Verify that the specified transform paths are valid.
By: Emiley J. : 2007-09-10
Description: You are probably attempting to install the Java 2 Runtime Environment, Standard Edition (JRE) or the JDK 1.4.xx version in your Windows server. But alas, a message box with the following error appears: Error applying transforms. Verify that the specified transform paths are valid. Here is the solution.
210. Using PrintWriter in Java
By: Abinaya : 2007-09-10
Description: Although using System.out to write to the console is still permissible under Java, its use is recommended mostly for debugging purposes or for sample programs, such as those found in this book. For real-world programs, the recommended method of writing to the console when using Java is through a PrintWriter stream. PrintWriter is one of the character-based classes. Using a character-based class for console output makes it easier to internationalize your program.