Java Standard Library Flashcards
JOptionPane
A GUI for text input and output located in javax.swing
showInputDialog(String prompt)
Prints the prompt and returns the string entered by user
showMessageDialog(String message)
Generates a message box
showConfirmDialog()
Generates a message box
showConfirmDialog(null, prompt, title, optionType)
Creates a confirmation window
java.lang
General support - string, integer, float, math
Package for general utilities
- random numbers
- currency
- calendar
- data structures
java.util
Package for formatting text
- dates
- currency
java.text
Package for basic graphics & GUIs
java.awt
Package extending awt with advanced GUIs
javax.swing
Package with functions for I/O and formatting
java.io
Package for writing applets
java.applet
Which package is automatically imported into all programs?
java.lang
String method for length
S.length();
String method for comparing the content of strings. Return type.
s.equals(t);
Boolean
String method for comparing lexicographically. Return type.
s.compareTo(t);
0 - equal
> 0 - First string greater
< 0 - Second string is greater
String method for comparing address references
==
String method for lexicographical comparison disregarding case
s.compareToIgnoreCase(t);
String method to access a character at a given index (0 to length - 1)
char c = s.charAt(0);
String method for changing case
String x = s.toLowerCase();
String x = s.toUpperCase;
Absolute value method
double x = Math.abs(-14.3);
Square Root Method
double x = Math.sqrt(2.0);
Trig methods
double x = Math.cos(y);
double x = Math.sin(y);
Powers method
double x = Math.pow(base, exponent);
Random numbers method
Return range
double x = Math.random();
0.0 to 1.0
The class that formats text
Number Format in java.text
Currency Conversion
Generate a currency object assigned to x
NumberFormat.getCurrencyInstance();
Generate the String
Double amount = 123.5
x.format(amount);
Percentage Conversion
Generate a percent object assigned to x
NumberFormat.getPercentInstance();
Generate a string & format
double taxrate = 0.079;
percent.format(taxrate);