Introduction to Programming in Java: Standard Libraries
Input and output libraries.
Here is a list of the input and output libraries that we use throughout the textbook.
The file stdlib.jar bundles together all of the I/O libraries above into a .jar file.
Accessing the libraries.
There are a number of ways to access the libraries:- Current directory.
The simplest method is to put the desired .java file
(such as StdIn.java)
in the same directory as the program you are writing.
Then, compile and execute as usual.
% javac MyProgram.java % java MyProgram
- Classpath.
The file stdlib.jar bundles together all of our
standard libraries into one file.
To access it, put stdlib.jar in the same directory as
the program you are writing.
Then, compile and execute as follows.
The -cp flag sets the classpath. The . tells Java to look in the current directory for .java and .class files (such as MyProgram.java and MyProgram.class). The stdlib.jar tells Java to also look in the .jar file. On OS X, the : separates directories in the classpath; on Windows the ; separates directories.OS X / Linux ------------ % javac -cp .:stdlib.jar MyProgram.java % java -cp .:stdlib.jar MyProgram Windows ------------ % javac -cp .;stdlib.jar MyProgram.java % java -cp .;stdlib.jar MyProgram
- Configure your IDE. You can configure your IDE to automatically include stdlib.jar in the classpath. In DrJava, it is Preferences -> Extra Classpath -> Add.
