The Core J2SE Libraries


The Core J2SE Libraries

The core libraries are things that can be used in any type of programming application. They include the basic I/O, math, system, String , and collection classes. Any reasonably sized Java program you write will make use of the core libraries. This section provides a snapshot view of four of the core packages most important to scientific and engineering programming.

java.io

The java.io package contains many of the classes and interfaces used for Java I/O operations. These are the elements you will use to read and write data. There are two main branches of the java.io package. The first defines classes and interfaces used to read or write byte data. The bytes can be read or written one at a time or an array of bytes can be processed . Byte I/O is useful for reading or writing things like images, objects, or sound files.

The second branch defines classes and interfaces used to read or write character data. The character I/O classes include FileReader and FileWriter , which are used to read or write character data to a file. The BufferedReader and BufferedWriter classes provide buffered I/O for more efficient reading and writing of character data. The StreamTokenizer class can be used to parse an input stream into tokens. This class can be used to parse the contents of an input file. The java.io package also defines many of the I/O exception classes. The Java I/O classes are covered in more detail in Chapter 25.

One of the significant additions under J2SE version 1.4 was the introduction of the java.nio packages to the Java API. These packages provide buffer classes for primitive data types to improve I/O performance, classes that define character set encoders and decoders to convert bytes to Unicode characters and vice versa, and a regular expression pattern matching capability. The java.nio packages are briefly discussed in Chapter 25.

java.lang

The java.lang class is unique in that it is implicitly imported into every Java program. You never have to write import java.lang.*; at the top of your program. This package contains the core classes that are used in a variety of Java programs. The contents of java.lang include the Object class, the superclass of all Java classes. The primitive variable wrapper classes can be found in java.lang as can the String class. The Throwable class is the superclass of all Java exceptions. The Math and StrictMath classes contain methods for the exponential, logarithm, square root, and trigonometric mathematical functions. The System class defines high-level functions that do things like terminate a program or invoke the system garbage collector. The java.lang package also contains some of the classes used in multithreaded programming applications.

java.math

The java.math package defines the BigDecimal and BigInteger classes for performing arbitrary-precision decimal and integer arithmetic. In addition to being able to specify the precision of mathematical operations using these classes, a user can specify what rounding procedures will be used.

java.util

The java.util package defines utility classes that are applicable to a wide range of programming applications. Included are the collections classes first discussed in Chapter 13. The Calendar , Date , and GregorianCalendar classes allow you to represent and manipulate dates and times. The Random class can be used to generate random numbers . The Locale class allows you to customize your applications for different countries and languages. The StringTokenizer class allows you to break up a String into substrings. This can be useful for parsing lines read from an input file.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net