JDK Dott. Ing. Leonardo Rigutini Dipartimento Ingegneria dell Informazione Università di Siena Via Roma 56 53100 SIENA Uff. 0577233606 rigutini@dii.unisi.it www.dii.unisi.it/~rigutini/
JDK
Libreria standard JAVA Fornisce una grande varietà di classi per facilitare lo sviluppo di applicazioni Organizzata come una gerarchia di packages Disponibile il JavaDOC, sia su JBuilder che in rete: http://java.sun.com/j2se/1.5.0/docs/index.html Vediamo le classi principali che potrebbero essere utili nello sviluppo di applicazioni
Gerarchia javadoc java java.lang java.io java.math java.applet java.sql java.net java.util java.text java.awt java.beans java.rmi java.security javax javax.swing javax.sql javax.xml
java.lang Tratto dal javadoc Class Summary Boolean Byte Character Double Float The Boolean class wraps a value of the primitive type boolean in an object. The Byte class wraps a value of primitive type byte in an object. The Character class wraps a value of the primitive type char in an object. The Double class wraps a value of the primitive type double in an object. The Float class wraps a value of primitive type float in an object.
java.lang Class Summary Integer Long Math String System Thread Throwable The Integer class wraps a value of the primitive type int in an object. The Long class wraps a value of the primitive type long in an object The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. The String class represents character strings. The System class contains several useful class fields and methods. A thread is a thread of execution in a program. The Throwable class is the superclass of all errors and exceptions in the Java language.
La classe Object Come già detto la classe Object è la classe root di tutte le classi Fornisce una serie di funzioni che normalmente devono essere sovrascritte (override) Vedere JavaDoc
Classi wrapper Come si vede esistono nel package molte classi che sembrano avere lo stesso nome dei tipi di dato semplici: Boolean, Double, Float, Integer, ecc Queste classi sono dette classi wrapper e sono utilizzate per wrappare i tipi di dato semplice in classi: double indica una variabile che memorizza valori con virgola di tipo double; Double è un oggetto che rappresenta un double che ha particolari metodi per la lettura, la conversione dei double, ecc Vedere il JavaDoc
Classe String La classe String rappresenta le stringhe di caratteri. Ogni parola, frase, documento è una stringa di caratteri. La classe String include metodi per esaminare i singoli caratteri, comparare stringhe, ricercare ed estrarre sottostringhe, portare tutto minuscolo o maiuscolo, concatenare ecc Vedere il JavaDoc
La classe math La classe Math mette a disposizioni funzioni matematiche statiche che possono essere quindi utilizzate senza necessità di istanziare oggetti di tipo Math: Es. double a=1.44; double b=3; double c=math.sqrt(a); c=1.2 double p=math.pow(a,b); p = 2,9859 Fornisce anche due costanti statiche di tipo double : Math.E numero di nepero (e=2,71) Math.PI pi greco (pi=3.14) Vedere il JavaDoc
La classe System La classe System contiene alcune variabili e funzioni di sistema: Lo stdout, sterr e stdin sono variabili statiche di questa classe Vedere il JavaDoc
La classe Thread se vogliamo utilizzare più istanze della nostra applicazione (applet, jsp, grafica ecc ) dovremmo lanciare più volte la classe java con il main desiderato. Questa soluzione comporta l esecuzione ogni volta di coambi di contesto che appesantiscono ancor di più il sistema: Utilizzo dei thread Lanciare un applicazione come thread significa creare nel contesto attuale un sotto-contesto in cui eseguire l applicazione lanciata come thread. Tale soluzione può essere utilizzata per eseguire operazioni in parallelo: Se dichiariamo una classe come figlia di un thread, essa può essere eseguita senza cambi di contesto.
Il package java.io Questo package fornisce classi per facilitare la lettura e scrittura di dati: Stream: oggetto che realizza un flusso di dati che possono essere letti o scritti Un file, lo stdout, stderr e stdin sono degli stream e sono wrappati da apposite classi
Il package java.io Class Summary BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter File FileInputStream FileOutputStream A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. The class implements a buffered output stream. Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. Write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. An abstract representation of file and directory pathnames. A FileInputStream obtains input bytes from a file in a file system. A file output stream is an output stream for writing data to a File or to a FileDescriptor.
Il package java.io Class Summary FileReader FileWriter InputStream OutputStream OutputStreamWriter PrintStream PrintWriter Reader Convenience class for reading character files. Convenience class for writing character files. This abstract class is the superclass of all classes representing an input stream of bytes. This abstract class is the superclass of all classes representing an output stream of bytes. An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset. A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Print formatted representations of objects to a text-output stream. Abstract class for reading character streams.
Il package java.io Class Summary StreamTokenizer StringReader StringWriter Writer The StreamTokenizer class takes an input stream and parses it into "tokens", allowing the tokens to be read one at a time. A character stream whose source is a string. A character stream that collects its output in a string buffer, which can then be used to construct a string. Abstract class for writing to character streams.
Il package java.util Questo package fornisce classi di utilità generale Le classi più importanti sono quelle che implementano le strutture dati dinamiche, timers e StringTokenizer: Le prime forniscono modi per memorizzare vettori, tabelle hash, liste, stack di dimensione variabili (dinamici) Le seconde forniscono classi per gestire il tempo nel codice L ultima invece fornisce una classe lettore di stringhe e permette di tagliare una stringa nei punti desiderati e quindi estrarre da un flusso continuo di parole dei tokens
Il package java.util Class Summary Collections Currency Date HashMap HashSet Hashtable Random This class consists exclusively of static methods that operate on or return collections. Represents a currency. The class Date represents a specific instant in time, with millisecond precision. Hash table based implementation of the Map interface. This class implements the Set interface, backed by a hash table (actually a HashMap instance). This class implements a hashtable, which maps keys to values. An instance of this class is used to generate a stream of pseudorandom numbers.
Il package java.util Class Summary Stack StringTokenizer Timer TreeMap TreeSet The Stack class represents a last-in-first-out (LIFO) stack of objects. The string tokenizer class allows an application to break a string into tokens. A facility for threads to schedule tasks for future execution in a background thread. Red-Black tree based implementation of the SortedMap interface. This class implements the Set interface, backed by a TreeMap instance. Vector The Vector class implements a growable array of objects.