/************************************************************************
* *
* java.lang: *
* *
* Interfaces: *
* Cloneable #Comparable Runnable *
* *
* Classes: *
* Boolean Double Object StringBuffer *
* Byte Float Process System *
* Character Integer Runtime Thread *
* Class Long SecurityManager ThreadGroup *
* ClassLoader Math Short Throwable *
* Compiler Number String Void *
* *
* #Character.Subset #Package *
* #Character.UnicodeBlock #RuntimePermission *
* #InheritableThreadLocal #ThreadLocal *
* *
* Exceptions: *
* ArithmeticException IndexOutOfBoundsException *
* ArrayIndexOutOfBoundsException InstantiationException *
* ArrayStoreException InterruptedException *
* ClassCastException NegativeArraySizeException *
* ClassNotFoundException NoSuchFieldException *
* CloneNotSupportedException NoSuchMethodException *
* Exception NullPointerException *
* IllegalAccessException NumberFormatException *
* IllegalArgumentException RuntimeException *
* IllegalMonitorStateException SecurityException *
* IllegalStateException StringIndexOutOfBoundsException*
* IllegalThreadStateException *
* *
* #UnsupportedOperationException *
* *
* Errors: *
* AbstractMethodError NoClassDefFoundError *
* ClassCircularityError NoSuchFieldError *
* ClassFormatError NoSuchMethodError *
* Error OutOfMemoryError *
* ExceptionInInitializerError StackOverflowError *
* IllegalAccessError ThreadDeath *
* IncompatibleClassChangeError UnknownError *
* InstantiationError UnsatisfiedLinkError *
* InternalError VerifyError *
* LinkageError VirtualMachineError *
* *
* #UnsupportedClassVersionError *
* *
************************************************************************/
package Test.Chris;
public class Java_lang implements Runnable {
public void run() { }
public static void main(String[] args) {
Java_lang obj = new Java_lang();
obj.exercise();
System.exit(0);
}
public void exercise() {
string();
stringbuffer();
math();
number();
voids();
booleans();
bytes();
characters();
character_subset();
character_unicodeblock();
integers();
shorts();
longs();
floats();
doubles();
system();
securitymanager();
runtimepermission();
object();
cloneable();
comparable();
process();
runtime();
packages();
classes();
classloader();
compiler();
thread();
threadgroup();
threadlocal();
inheritablethreadlocal();
throwable();
runnable();
}
/*********************************************************************
* *
* String: character strings *
* *
* #CASE_INSENSITIVE_ORDER *
* *
* charAt getChars startsWith *
* compareTo hashCode substring *
* concat indexOf toCharArray *
* copyValueOf intern toLowerCase *
* endsWith lastIndexOf toString *
* equals length toUpperCase *
* equalsIgnoreCase regionMatches trim *
* getBytes replace valueOf *
* *
* #compareToIgnoreCase *
* *
*********************************************************************/
private void string() {
int i = 0;
boolean b;
char c;
char[] d;
byte[] e;
String s;
String t;
java.util.Comparator m;
s = "Test String\n"; // literal strings auto allocate object
s = "i = " + "0"; // only operator for strings is addition
s = "i = " + i; // auto cast to string
s = "Chris";
t = "Chr";
t = t.concat("is"); // concatenates string to end
b = (s != t); // compares object pointers not the values
b = s.equals(t); // compares string to the specified object
b = s.equalsIgnoreCase(t); // compares string to another object - ignores case
i = s.compareTo(t); // compares two strings lexicographically (0=equal)
b = s.startsWith("Ch"); // tests if string starts with the specified prefix
b = s.startsWith("ri", 2); // tests with offset into string
b = s.endsWith("is"); // tests if string ends with the specified suffix
i = s.length(); // length of string
c = s.charAt(0); // returns character at the specified index
t = s.toLowerCase(); // converts string to lowercase
t = s.toUpperCase(); // converts string to uppercase
t = s.replace('C', 'X'); // returns new string - replacing characters of arg1 with arg2
t = s.trim(); // removes white space from both ends of string
t = s.substring(2); // returns new substring from index position to end of string
t = s.substring(2,5); // returns new substring from index position to end position-1
i = s.indexOf('h'); // index in string of first occurrence of char (-1=!found)
i = s.indexOf('r', 2); // index - search forward starting at the specified index
i = s.indexOf("ri"); // index in string of first occurrence of substring
i = s.indexOf("ri", 2); // index - search forward starting at the specified index
i = s.lastIndexOf('h'); // index in string of last occurrence of char (-1=!found)
i = s.lastIndexOf('r', 2); // index - search backward starting at specified index
i = s.lastIndexOf("ri"); // index in string of last occurrence of substring
i = s.lastIndexOf("ri", 2); // index - search backward starting at specified index
d = s.toCharArray(); // create new character array from string
s.getChars(1, 2, d, 0); // copies characters from string into the destination char array
t = String.copyValueOf(d); // returns string that is equivalent to the specified char array
t = String.copyValueOf(d, 3, 2); // returns string - with subarray offset and length
e = s.getBytes(); // convert string into byte array
s = String.valueOf(true); // convert boolean to string
s = String.valueOf('A'); // convert char to string
s = String.valueOf(d); // convert char array to string
s = String.valueOf(2.0); // convert double to string
s = String.valueOf(2.0F); // convert float to string
s = String.valueOf(2); // convert int to string
s = String.valueOf(2L); // convert long to string
s = String.valueOf(d, 3, 2); // convert subarray of char array
t = s.toString(); // returns this object (which is already a string)
i = s.hashCode(); // returns hashcode for this string
b = s.regionMatches(true,0,t,1,3);// Tests if two string regions equal (ignorecase,ofs,str,ofs,len)
t = s.intern(); // returns same contents as string - from a pool of unique strings
m = String.CASE_INSENSITIVE_ORDER;// comparator that orders String objects as compareToIgnoreCase
i = s.compareToIgnoreCase(s); // compares strings lexicographically (ignoring case)
}
/*********************************************************************
* *
* StringBuffer: mutable sequence of characters *
* *
* append getChars setCharAt *
* capacity insert setLength *
* charAt length toString *
* ensureCapacity reverse *
* *
* #delete #deleteCharAt #substring *
* *
*********************************************************************/
private void stringbuffer() {
int i = 0;
char c;
char[] d = new char[20];
StringBuffer s;
String t;
s = new StringBuffer("Chris");
i = s.length(); // returns the length (character count) of string buffer
i = s.capacity(); // returns the current capacity of string buffer
s.ensureCapacity(40); // ensures the min capacity of the buffer
s.setLength(5); // sets length of string buffer (chops off excess chars)
s.charAt(3); // get character at the specified index of string buffer
s.setCharAt(3, 'X'); // set character at the specified index of string buffer
s.reverse(); // reverse the sequence of chars within string buffer
t = s.toString(); // converts to string representing the data
//%2 s.getChars(3, 2, d, 0); // chars are copied from this string buffer into char array
// can append/insert: boolean, byte, char, char[], short,
// int, long, float, double, String, Object
s.append(" was"); // append to end of string buffer
s.append(" here ").append(12.34); // multiple appends on one line
s.insert(5, "4321"); // insert string at index
s = s.delete(5, 6); // removes char in a substring
s = s.deleteCharAt(1); // removes char at the specified position
t = s.substring(3); // returns subsequence of characters
}
/*********************************************************************
* *
* Math: basic numeric operations *
* *
* E PI *
* *
* abs exp random *
* acos floor rint *
* asin IEEEremainder round *
* atan log sin *
* atan2 max sqrt *
* ceil min tan *
* cos pow *
* *
* #toDegrees #toRadians *
* *
*********************************************************************/
private void math() {
int i;
double x;
double y = 0.5;
x = Math.PI; // pi, the ratio of the circumference of a circle to its diameter
x = Math.E; // e, the base of the natural logarithms
i = Math.abs(-2); // absolute value (int, long, float or double)
i = Math.max(5,4); // greater of two values (int, long, float or double)
i = Math.min(5,4); // smaller of two values (int, long, float or double)
i = Math.round(1.5F); // closest value to the argument (float->int; double->long)
x = Math.ceil(1.5); // smallest double value that is not less than the
// argument and is equal to a mathematical integer
x = Math.floor(1.5); // largest double value that is not greater than the
// argument and is equal to a mathematical integer
x = Math.rint(1.5); // round to closest integer to the argument
x = Math.IEEEremainder(3.0, 2.0); // remainder operation (IEEE 754 standard)
x = Math.sqrt(25.0); // square root
x = Math.pow(5.0, 2.0); // power of x^^y
x = Math.exp(5.0); // exponential number e raised to power
x = Math.log(2.0); // natural logarithm (base e) of a double value
x = Math.random(); // random number between 0.0 and 1.0
x = Math.sin(y); // trigonometric sine of an angle
x = Math.cos(y); // trigonometric cosine of an angle
x = Math.tan(y); // trigonometric tangent of an angle
x = Math.asin(y); // arc sine of an angle, range of -pi/2 through pi/2
x = Math.acos(y); // arc cosine of an angle, range of 0.0 through pi
x = Math.atan(y); // arc tangent of an angle, range of -pi/2 through pi/2
x = Math.atan2(x,y); // Converts rectangular coordinates (b, a) to polar (r, theta)
x = Math.toDegrees(y); // converts an angle measured in radians to the equivalent angle measured in degrees
x = Math.toRadians(y); // converts an angle measured in degrees to the equivalent angle measured in radians
}
/*********************************************************************
* *
* Number: abstract for number classes (abstract) *
* *
* byteValue floatValue longValue *
* doubleValue intValue shortValue *
* *
*********************************************************************/
class cmrNumber extends Number {
private double num = 0.0;
public cmrNumber(double x) {
num = x;
}
public byte byteValue() { return (byte)num; }
public int intValue() { return (int)num; }
public short shortValue() { return (short)num; }
public long longValue() { return (long)num; }
public float floatValue() { return (float)num; }
public double doubleValue() { return num; }
}
private void number() {
cmrNumber x = new cmrNumber(34.56);
byte b = x.byteValue(); // value of number as byte
int i = x.intValue(); // value of number as int
short j = x.shortValue(); // value of number as short
long k = x.longValue(); // value of number as long
float y = x.floatValue(); // value of number as float
double z = x.doubleValue(); // value of number as double
}
/*********************************************************************
* *
* Void: void type - can not be instanced *
* *
* TYPE *
* *
*********************************************************************/
private void voids() {
// The Class object representing the primitive Java type void - cannot instantiate
Object x = new Object();
if (x instanceof Void) { }
}
/*********************************************************************
* *
* Boolean: class wrapper for boolean primitive *
* *
* FALSE TRUE TYPE *
* *
* booleanValue getBoolean toString *
* equals hashCode valueOf *
* *
*********************************************************************/
private void booleans() {
int i;
String s;
boolean f;
Boolean b = new Boolean(true);
b = Boolean.valueOf("true"); // returns the boolean value represented by the specified String
b = Boolean.FALSE; // the Boolean object corresponding to the primitive value false
b = Boolean.TRUE; // the Boolean object corresponding to the primitive value true
f = b.booleanValue(); // returns the value of this Boolean object as a boolean
f = b.equals(Boolean.TRUE); // true if Boolean object contains the same boolean value
f = b.getBoolean("CLASSPATH"); // true if system property is equal to the string "true"
s = b.toString(); // returns a String object representing this Boolean's value
i = b.hashCode(); // returns a hash code for this Boolean
Class cls = b.TYPE; // the Class object representing the primitive type boolean
}
/*********************************************************************
* *
* Byte: class wrapper for byte primitive *
* *
* MAX_VALUE MIN_VALUE TYPE *
* *
* byteValue floatValue parseByte *
* decode hashCode shortValue *
* doubleValue intValue toString *
* equals longValue valueOf *
* *
* #compareTo *
* *
*********************************************************************/
private void bytes() {
boolean f;
byte a;
short i;
int j;
long k;
float x;
double y;
String s;
Byte b = new Byte((byte)123);
Byte c = b;
b = Byte.decode("102"); // decodes a String into a Byte
b = Byte.valueOf("-99"); // returns a new Byte object initialized to converted String value
b = Byte.valueOf("6F", 16); // returns a new Byte object initialized to converted String value
a = Byte.parseByte("99"); // returns a byte value of a string
a = Byte.parseByte("7F", 16); // returns a byte value of a string - with radix
i = Byte.MIN_VALUE; // the maximum value a Byte can have
i = Byte.MAX_VALUE; // the minimum value a Byte can have
a = b.byteValue(); // returns the value of this Byte as a byte
i = b.shortValue(); // returns the value of this Byte as a short
j = b.intValue(); // returns the value of this Byte as an int
k = b.longValue(); // returns the value of this Byte as a long
x = b.floatValue(); // returns the value of this Byte as a float
y = b.doubleValue(); // returns the value of this Byte as a double
j = b.hashCode(); // returns a hashcode for this Byte
s = b.toString(); // returns a String object representing this Byte's value
s = Byte.toString((byte)123); // returns a new String object representing the specified Byte
f = b.equals(c); // compares this object to the specified object
Class cls = b.TYPE; // the Class object representing the primitive type byte
j = b.compareTo(new Byte("15")); // compares two Bytes numerically
}
/*********************************************************************
* *
* Character: class wrapper for char primitive *
* *
* COMBINING_SPACING_MARK MODIFIER_LETTER *
* CONNECTOR_PUNCTUATION MODIFIER_SYMBOL *
* CONTROL NON_SPACING_MARK *
* CURRENCY_SYMBOL OTHER_LETTER *
* DASH_PUNCTUATION OTHER_NUMBER *
* DECIMAL_DIGIT_NUMBER OTHER_PUNCTUATION *
* ENCLOSING_MARK OTHER_SYMBOL *
* END_PUNCTUATION PARAGRAPH_SEPARATOR *
* FORMAT PRIVATE_USE *
* LETTER_NUMBER SPACE_SEPARATOR *
* LINE_SEPARATOR START_PUNCTUATION *
* LOWERCASE_LETTER SURROGATE *
* MATH_SYMBOL TITLECASE_LETTER *
* MAX_RADIX TYPE *
* MAX_VALUE UNASSIGNED *
* MIN_RADIX UPPERCASE_LETTER *
* MIN_VALUE *
* *
* !isJavaLetter !isSpace *
* !isJavaLetterOrDigit *
* *
* charValue isLetter *
* digit isLetterOrDigit *
* equals isLowerCase *
* forDigit isSpaceChar *
* getNumericValue isTitleCase *
* getType isUnicodeIdentifierPart *
* hashCode isUnicodeIdentifierStart *
* isDefined isUpperCase *
* isDigit isWhitespace *
* isIdentifierIgnorable toLowerCase *
* isISOControl toString *
* isJavaIdentifierPart toTitleCase *
* isJavaIdentifierStart toUpperCase *
*
* #compareTo
* *
*********************************************************************/
private void characters() {
int i;
boolean b;
String s;
double x;
char c = 'X';
Character d = new Character('X');
Character e = new Character('X');
i = Character.MIN_VALUE; // constant value of this field is the smallest value of type char
i = Character.MAX_VALUE; // constant value of this field is the largest value of type char
i = Character.MIN_RADIX; // minimum radix available for conversion to and from Strings
i = Character.MAX_RADIX; // maximum radix available for conversion to and from Strings
b = Character.isUpperCase(c); // test if uppercase
b = Character.isLowerCase(c); // test if lowercase
b = Character.isDigit(c); // test if digit
b = Character.isLetter(c); // test if letter
b = Character.isLetterOrDigit(c); // test if letter or digit
b = Character.isSpaceChar(c); // test if Unicode space character
b = Character.isDefined(c); // test if has defined meaning in Unicode
b = Character.isWhitespace(c); // test if white space
b = Character.isISOControl(c); // test if ISO control character
b = Character.isTitleCase(c); // test if titlecase character
b = Character.isIdentifierIgnorable(c); // test if ignorable char in Java or Unicode identifier
b = Character.isJavaIdentifierPart(c); // test if may be part of Java identifier (not 1st char)
b = Character.isJavaIdentifierStart(c); // test if permissible as the first char in Java identifier
b = Character.isUnicodeIdentifierPart(c); // test if may be part of Unicode identifier (not 1st char)
b = Character.isUnicodeIdentifierStart(c);// test if permissible as first char in a Unicode identifier
c = Character.toLowerCase(c); // convert to lowercase
c = Character.toUpperCase(c); // convert to uppercase
c = Character.toTitleCase(c); // convert to titlecase
x = Character.digit('F', 16); // numeric value of char in specified radix
c = Character.forDigit(15, 16); // character for a specific digit in specified radix
i = Character.getNumericValue(c); // Unicode numeric value of char as nonnegative integer
b = d.equals(e); // Compares this object against the specified object
i = d.charValue(); // value of this Character object
s = d.toString(); // convert to string
i = d.hashCode(); // returns hash code for this Character
Class cls = d.TYPE; // the Class object representing the primitive type char
switch (d.getType('A')) {
case Character.COMBINING_SPACING_MARK: break;
case Character.CONNECTOR_PUNCTUATION: break;
case Character.CONTROL: break;
case Character.CURRENCY_SYMBOL: break;
case Character.DASH_PUNCTUATION: break;
case Character.DECIMAL_DIGIT_NUMBER: break;
case Character.ENCLOSING_MARK: break;
case Character.END_PUNCTUATION: break;
case Character.FORMAT: break;
case Character.LETTER_NUMBER: break;
case Character.LINE_SEPARATOR: break;
case Character.LOWERCASE_LETTER: break;
case Character.MATH_SYMBOL: break;
case Character.MODIFIER_LETTER: break;
case Character.MODIFIER_SYMBOL: break;
case Character.NON_SPACING_MARK: break;
case Character.OTHER_LETTER: break;
case Character.OTHER_NUMBER: break;
case Character.OTHER_PUNCTUATION: break;
case Character.OTHER_SYMBOL: break;
case Character.PARAGRAPH_SEPARATOR: break;
case Character.PRIVATE_USE: break;
case Character.SPACE_SEPARATOR: break;
case Character.START_PUNCTUATION: break;
case Character.SURROGATE: break;
case Character.TITLECASE_LETTER: break;
case Character.UNASSIGNED: break;
case Character.UPPERCASE_LETTER: break;
}
i = d.compareTo(new Character('X')); // compares two chars numerically
}
/*********************************************************************
* *
* #Character.Subset: represent subsets of Unicode character set *
* *
* equals hashcode toString *
* *
*********************************************************************/
private void character_subset() {
/* TO BE DETERMINED
boolean b;
int i;
String s;
Character d = new Character('X');
Character.Subset x = d.new Subset("CMR");
Character.Subset y = d.new Subset("CUS");
b = x.equals(y); // compares two Subset objects for equality
i = x.hashCode(); // standard hash code
s = x.toString(); // name of this subset
*/
}
/*********************************************************************
* *
* #Character.UnicodeBlock: char subsets for Unicode 2.0 *
* *
* ALPHABETIC_PRESENTATION_FORMS HALFWIDTH_AND_FULLWIDTH_FORMS*
* ARABIC HANGUL_COMPATIBILITY_JAMO *
* ARABIC_PRESENTATION_FORMS_A HANGUL_JAMO *
* ARABIC_PRESENTATION_FORMS_B HANGUL_SYLLABLES *
* ARMENIAN HEBREW *
* ARROWS HIRAGANA *
* BASIC_LATIN IPA_EXTENSIONS *
* BENGALI KANBUN *
* BLOCK_ELEMENTS KANNADA *
* BOPOMOFO KATAKANA *
* BOX_DRAWING LAO *
* CJK_COMPATIBILITY LATIN_1_SUPPLEMENT *
* CJK_COMPATIBILITY_FORMS LATIN_EXTENDED_A *
* CJK_COMPATIBILITY_IDEOGRAPHS LATIN_EXTENDED_ADDITIONAL *
* CJK_SYMBOLS_AND_PUNCTUATION LATIN_EXTENDED_B *
* CJK_UNIFIED_IDEOGRAPHS LETTERLIKE_SYMBOLS *
* COMBINING_DIACRITICAL_MARKS MALAYALAM *
* COMBINING_HALF_MARKS MATHEMATICAL_OPERATORS *
* COMBINING_MARKS_FOR_SYMBOLS MISCELLANEOUS_SYMBOLS *
* CONTROL_PICTURES MISCELLANEOUS_TECHNICAL *
* CURRENCY_SYMBOLS NUMBER_FORMS *
* CYRILLIC OPTICAL_CHARACTER_RECOGNITION*
* DEVANAGARI ORIYA *
* DINGBATS PRIVATE_USE_AREA *
* ENCLOSED_ALPHANUMERICS SMALL_FORM_VARIANTS *
* ENCLOSED_CJK_LETTERS_AND_MONTHS SPACING_MODIFIER_LETTERS *
* GENERAL_PUNCTUATION SPECIALS *
* GEOMETRIC_SHAPES SUPERSCRIPTS_AND_SUBSCRIPTS *
* GEORGIAN SURROGATES_AREA *
* GREEK TAMIL *
* GREEK_EXTENDED TELUGU *
* GUJARATI THAI *
* GURMUKHI TIBETAN *
* *
* of *
* *
*********************************************************************/
private void character_unicodeblock() {
Character.UnicodeBlock x;
x = Character.UnicodeBlock.of('A');
x = Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS;
x = Character.UnicodeBlock.ARABIC;
x = Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A;
x = Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B;
x = Character.UnicodeBlock.ARMENIAN;
x = Character.UnicodeBlock.ARROWS;
x = Character.UnicodeBlock.BASIC_LATIN;
x = Character.UnicodeBlock.BENGALI;
x = Character.UnicodeBlock.BLOCK_ELEMENTS;
x = Character.UnicodeBlock.BOPOMOFO;
x = Character.UnicodeBlock.BOX_DRAWING;
x = Character.UnicodeBlock.CJK_COMPATIBILITY;
x = Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS;
x = Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS;
x = Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION;
x = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS;
x = Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS;
x = Character.UnicodeBlock.COMBINING_HALF_MARKS;
x = Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS;
x = Character.UnicodeBlock.CONTROL_PICTURES;
x = Character.UnicodeBlock.CURRENCY_SYMBOLS;
x = Character.UnicodeBlock.CYRILLIC;
x = Character.UnicodeBlock.DEVANAGARI;
x = Character.UnicodeBlock.DINGBATS;
x = Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS;
x = Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS;
x = Character.UnicodeBlock.GENERAL_PUNCTUATION;
x = Character.UnicodeBlock.GEOMETRIC_SHAPES;
x = Character.UnicodeBlock.GEORGIAN;
x = Character.UnicodeBlock.GREEK;
x = Character.UnicodeBlock.GREEK_EXTENDED;
x = Character.UnicodeBlock.GUJARATI;
x = Character.UnicodeBlock.GURMUKHI;
x = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS;
x = Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO;
x = Character.UnicodeBlock.HANGUL_JAMO;
x = Character.UnicodeBlock.HANGUL_SYLLABLES;
x = Character.UnicodeBlock.HEBREW;
x = Character.UnicodeBlock.HIRAGANA;
x = Character.UnicodeBlock.IPA_EXTENSIONS;
x = Character.UnicodeBlock.KANBUN;
x = Character.UnicodeBlock.KANNADA;
x = Character.UnicodeBlock.KATAKANA;
x = Character.UnicodeBlock.LAO;
x = Character.UnicodeBlock.LATIN_1_SUPPLEMENT;
x = Character.UnicodeBlock.LATIN_EXTENDED_A;
x = Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL;
x = Character.UnicodeBlock.LATIN_EXTENDED_B;
x = Character.UnicodeBlock.LETTERLIKE_SYMBOLS;
x = Character.UnicodeBlock.MALAYALAM;
x = Character.UnicodeBlock.MATHEMATICAL_OPERATORS;
x = Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS;
x = Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL;
x = Character.UnicodeBlock.NUMBER_FORMS;
x = Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION;
x = Character.UnicodeBlock.ORIYA;
x = Character.UnicodeBlock.PRIVATE_USE_AREA;
x = Character.UnicodeBlock.SMALL_FORM_VARIANTS;
x = Character.UnicodeBlock.SPACING_MODIFIER_LETTERS;
x = Character.UnicodeBlock.SPECIALS;
x = Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS;
x = Character.UnicodeBlock.SURROGATES_AREA;
x = Character.UnicodeBlock.TAMIL;
x = Character.UnicodeBlock.TELUGU;
x = Character.UnicodeBlock.THAI;
x = Character.UnicodeBlock.TIBETAN;
}
/*********************************************************************
* *
* Short: class wrapper for short primitive *
* *
* MAX_VALUE MIN_VALUE TYPE *
* *
* byteValue floatValue parseShort *
* decode hashCode shortValue *
* doubleValue intValue toString *
* equals longValue valueOf *
* *
* #compareTo *
* *
*********************************************************************/
private void shorts() {
boolean f;
int i;
short j;
long k;
byte n;
float x;
double y;
String s;
Short b = new Short((short)1234);
Short a = b;
b = Short.valueOf("2341"); // convert string to short
b = Short.valueOf("FFF", 16); // convert string to short - with radix
b = Short.decode("1040"); // decodes String into a Short
j = Short.parseShort("4210"); // parses string as a signed decimal short
j = Short.parseShort("F0F", 16); // parses string as a signed short in specified radix
i = Short.MAX_VALUE; // maximum value a Short can have
i = Short.MIN_VALUE; // minimum value a Short can have
n = b.byteValue(); // returns the value of this Short as a byte
j = b.shortValue(); // returns value of this Short as a short
i = b.intValue(); // returns value of this Short as an int
k = b.longValue(); // returns value of this Short as a long
x = b.floatValue(); // returns the value of this Short as a float
y = b.doubleValue(); // returns the value of this Short as a double
s = b.toString(); // returns String object representing this Short's value
s = Short.toString((short)4321); // returns new String object representing the specified Short
i = b.hashCode(); // returns a hashcode for this Short
f = b.equals(a); // compares this object to the specified object
Class cls = b.TYPE; // the Class object representing the primitive type short
i = b.compareTo(a); // compares two Shorts numerically
}
/*********************************************************************
* *
* Integer: class wrapper for int primitive *
* *
* MAX_VALUE MIN_VALUE TYPE *
* *
* byteValue hashCode toHexString *
* decode intValue toOctalString *
* doubleValue longValue toString *
* equals parseInt valueOf *
* floatValue shortValue *
* getInteger toBinaryString *
* *
* #compareTo *
* *
*********************************************************************/
private void integers() {
boolean f;
int i;
short j;
long k;
byte n;
float x;
double y;
String s;
Integer b = new Integer(1234);
Integer a = b;
b = Integer.getInteger("version");// integer value of system property with the specified name
b = Integer.valueOf("60000"); // returns new Integer object initialized to value of String
b = Integer.valueOf("FFFF", 16); // returns new Integer object initialized to value of String - radix
b = Integer.decode("1234"); // decodes string into an Integer
i = Integer.parseInt("4321"); // parses the string argument as a signed decimal integer
i = Integer.parseInt("F0F0", 16); // parses the string argument as a signed decimal integer - radix
s = Integer.toBinaryString(123); // creates string from integer arg as unsigned integer in base 2
s = Integer.toOctalString(123); // creates string from integer arg as unsigned integer in base 8
s = Integer.toHexString(123); // creates string from integer arg as unsigned integer in base 16
s = Integer.toString(1234); // returns new String object representing the specified integer
s = Integer.toString(127, 16); // returns new String object representing the specified integer
i = Integer.MAX_VALUE; // the largest value of type int
i = Integer.MIN_VALUE; // the smallest value of type int
n = b.byteValue(); // returns the value of this Integer as a byte
j = b.shortValue(); // returns the value of this Integer as a short
i = b.intValue(); // returns the value of this Integer as an int
k = b.longValue(); // returns the value of this Integer as a long
x = b.floatValue(); // returns the value of this Integer as a float
y = b.doubleValue(); // returns the value of this Integer as a double
s = b.toString(); // returns String object representing this Integer's value
f = b.equals(a); // compares this object to the specified object
i = b.hashCode(); // returns hashcode for this Integer
Class cls = b.TYPE; // the Class object representing the primitive type int
i = b.compareTo(a); // compares two Integers numerically
}
/*********************************************************************
* *
* Long: class wrapper for long primitive *
* *
* MAX_VALUE MIN_VALUE TYPE *
* *
* byteValue hashCode toBinaryString *
* doubleValue intValue toHexString *
* equals longValue toOctalString *
* floatValue parseLong toString *
* getLong shortValue valueOf *
* *
* #compareTo #decode *
* *
*********************************************************************/
private void longs() {
boolean f;
int i;
short j;
long k;
byte n;
float x;
double y;
String s;
Long b = new Long(1234);
Long a = b;
b = Long.getLong("version"); // Long value of system property with the specified name
b = Long.valueOf("60000"); // returns new Long object initialized to value of String
b = Long.valueOf("FFFF", 16); // returns new Long object initialized to value of String - radix
k = Long.parseLong("4321"); // parses the string argument as a signed decimal Long
k = Long.parseLong("F0F0", 16); // parses the string argument as a signed decimal Long - radix
s = Long.toBinaryString(123); // creates string from Long arg as unsigned Long in base 2
s = Long.toOctalString(123); // creates string from Long arg as unsigned Long in base 8
s = Long.toHexString(123); // creates string from Long arg as unsigned Long in base 16
s = Long.toString(1234); // returns new String object representing the specified Long
s = Long.toString(127, 16); // returns new String object representing the specified Long
k = Long.MAX_VALUE; // the largest value of type long
k = Long.MIN_VALUE; // the smallest value of type long
n = b.byteValue(); // returns the value of this Long as a byte
j = b.shortValue(); // returns the value of this Long as a short
i = b.intValue(); // returns the value of this Long as an int
k = b.longValue(); // returns the value of this Long as a long
x = b.floatValue(); // returns the value of this Long as a float
y = b.doubleValue(); // returns the value of this Long as a double
s = b.toString(); // returns String object representing this Long's value
f = b.equals(a); // compares this object to the specified object
i = b.hashCode(); // returns hashcode for this Long
Class cls = b.TYPE; // the Class object representing the primitive type long
i = b.compareTo(a); // compares two Longs numerically
b = Long.decode("1234"); // decodes string into a Long
}
/*********************************************************************
* *
* Float: class wrapper for float primitive *
* *
* MAX_VALUE NEGATIVE_INFINITY POSITIVE_INFINITY *
* MIN_VALUE NaN TYPE *
* *
* byteValue hashCode longValue *
* doubleValue intBitsToFloat shortValue *
* equals intValue toString *
* floatToIntBits isInfinite valueOf *
* floatValue isNaN *
* *
* #compareTo #parseFloat *
* *
*********************************************************************/
private void floats() {
boolean f;
int i;
short j;
long k;
byte n;
float x;
double y;
String s;
Float b = new Float(12.34);
Float a = b;
b = Float.valueOf("12.34"); // returns floating point value represented by the specified String
s = Float.toString(12.34F); // returns new String object representing the specified Long
i = Float.floatToIntBits(12.34F); // returns bit represention of a single-float value
x = Float.intBitsToFloat(i); // returns the single-float corresponding to a given bit represention
f = Float.isInfinite(12.34F); // returns true if specified number is infinitely large in magnitude
f = Float.isNaN(12.34F); // returns true if specified number is Not-a-Number (NaN)
x = Float.MIN_VALUE; // the largest positive value of type float
x = Float.MAX_VALUE; // the smallest positive value of type float
x = Float.NaN; // the NaN value of type float
x = Float.NEGATIVE_INFINITY; // the negative infinity of type float
x = Float.POSITIVE_INFINITY; // the positive infinity of type float
n = b.byteValue(); // returns the value of this Float as a byte
j = b.shortValue(); // returns the value of this Float as a short
i = b.intValue(); // returns the value of this Float as an int
k = b.longValue(); // returns the value of this Float as a long
x = b.floatValue(); // returns the value of this Float as a float
y = b.doubleValue(); // returns the value of this Float as a double
s = b.toString(); // returns String object representing this Float's value
f = b.isInfinite(); // returns true if Float value is infinitely large in magnitude
f = b.isNaN(); // returns true if Float value is Not-a-Number (NaN)
f = b.equals(a); // compares this object to the specified object
i = b.hashCode(); // returns hashcode for this Float
Class cls = b.TYPE; // the Class object representing the primitive type float
i = b.compareTo(a); // compares two Floats numerically
x = Float.parseFloat("1.23"); // parses the string argument as a Float
}
/*********************************************************************
* *
* Double: class wrapper for double primitive *
* *
* MAX_VALUE NEGATIVE_INFINITY POSITIVE_INFINITY *
* MIN_VALUE NaN TYPE *
* *
* byteValue hashCode longValue *
* doubleToLongBits intValue shortValue *
* doubleValue isInfinite toString *
* equals isNaN valueOf *
* floatValue longBitsToDouble *
* *
* #compareTo #parseDouble *
* *
*********************************************************************/
private void doubles() {
boolean f;
int i;
short j;
long k;
byte n;
float x;
double y;
String s;
Double b = new Double(12.34);
Double a = b;
b = Double.valueOf("12.34"); // returns floating point value represented by the specified String
s = Double.toString(12.34); // returns new String object representing the specified Long
k = Double.doubleToLongBits(1.2); // returns bit represention of a double value
y = Double.longBitsToDouble(k); // returns the double corresponding to a given bit represention
f = Double.isInfinite(12.34); // returns true if specified number is infinitely large in magnitude
f = Double.isNaN(12.34); // returns true if specified number is Not-a-Number (NaN)
y = Double.MIN_VALUE; // the largest positive value of type double
y = Double.MAX_VALUE; // the smallest positive value of type double
y = Double.NaN; // the NaN value of type double
y = Double.NEGATIVE_INFINITY; // the negative infinity of type double
y = Double.POSITIVE_INFINITY; // the positive infinity of type double
n = b.byteValue(); // returns the value of this Double as a byte
j = b.shortValue(); // returns the value of this Double as a short
i = b.intValue(); // returns the value of this Double as an int
k = b.longValue(); // returns the value of this Double as a long
x = b.floatValue(); // returns the value of this Double as a float
y = b.doubleValue(); // returns the value of this Double as a double
s = b.toString(); // returns String object representing this Double's value
f = b.isInfinite(); // returns true if Double value is infinitely large in magnitude
f = b.isNaN(); // returns true if Double value is Not-a-Number (NaN)
f = b.equals(a); // compares this object to the specified object
i = b.hashCode(); // returns hashcode for this Double
Class cls = b.TYPE; // the Class object representing the primitive type double
i = b.compareTo(a); // compares two Doubles numerically
y = Double.parseDouble("1.23"); // parses the string argument as a Double
}
/*********************************************************************
* *
* System: several useful class fields and methods *
* *
* err in out *
* *
* !getenv *
* *
* arraycopy getSecurityManager setErr *
* currentTimeMillis identityHashCode setIn *
* exit load setOut *
* gc loadLibrary setProperties *
* getProperties runFinalization setSecurityManager*
* getProperty runFinalizersOnExit *
* *
* #mapLibraryName #setProperty *
* *
* System.getProperties: *
* %awt.toolkit java.home path.separator *
* %file.encoding java.vendor user.dir *
* %file.encoding.pkg java.vendor.url user.home *
* file.separator %java.vendor.url.bug %user.language *
* line.separator %java.version user.name *
* java.class.path os.arch user.region *
* java.class.version os.name %user.timezone *
* %java.compiler os.version *
* *
* #java.vm.specification.version #java.vm.name *
* #java.vm.specification.vendor #java.specification.version *
* #java.vm.specification.name #java.specification.vendor *
* #java.vm.version #java.specification.name *
* #java.vm.vendor *
* *
*********************************************************************/
public void system(){
int i;
long n;
String s;
java.util.Properties p;
java.util.Enumeration z;
SecurityManager m;
byte[] c = {0x30, 0x31, 0x32, 0x33, 0x34, 0x33, 0x39};
byte[] d = {0x40, 0x41, 0x42, 0x43, 0x44, 0x43, 0x49};
java.io.ByteArrayInputStream ios = new java.io.ByteArrayInputStream(c);
//System.setErr(System.out); // reassigns the "standard" error output stream
//System.setOut(System.err); // reassigns the "standard" output stream
System.setIn(ios); // reassigns the "standard" input stream
System.out.println("System.out"); // standard output stream
System.err.println("System.err"); // standard error output stream
try {
i = System.in.read(); // standard input stream
} catch(java.io.IOException e) {
}
i = System.identityHashCode(c); // returns default hashcode for the given object
n = System.currentTimeMillis(); // returns the current time in milliseconds
System.arraycopy(c, 2, d, 1, 1); // copies array from source array to destination array
s = System.getProperty("os.name");// gets the system property indicated by the specified key
s = System.getProperty("x", "5"); // gets the system property indicated by the specified key - default
p = System.getProperties(); // determines the current system properties
z = p.propertyNames(); // returns an enumeration of the values in this hashtable
while (z.hasMoreElements()) {
s = (String)z.nextElement();
// System.out.println(s + " = " + System.getProperty(s));
}
System.setProperties(p); // sets the system properties to the Properties argument
m = System.getSecurityManager(); // gets the system security interface (see SecurityManager)
System.setSecurityManager(m); // sets the System security
System.runFinalization(); // runs the finalization methods of any objects pending finalization
//%2 System.runFinalizersOnExit(true); // enable or disable finalization on exit
System.gc(); // runs the garbage collector
//System.exit(1); // terminates the currently running Java Virtual Machine
s = System.setProperty("x", "5"); // sets system property
/* TO BE DETERMINED
System.load(String) // loads the specified filename as a dynamic library
System.loadLibrary(String) // loads the system library specified by the libname argument
s = System.mapLibraryName(String); // maps lib name into string representing a native library
*/
}
/*********************************************************************
* *
* Runtime: application interface with runtime environment *
* *
* !getLocalizedInputStream *
* *
* exec getRuntime runFinalization *
* exit load totalMemory *
* freeMemory loadLibrary traceInstructions *
* gc %runFinalizersOnExit traceMethodCalls *
* *
* *
*********************************************************************/
private void runtime() {
long i;
Runtime x = Runtime.getRuntime(); // runtime object associated with current Java application
i = x.freeMemory(); // amount of free memory in the system
i = x.totalMemory(); // total amount of memory in the Java Virtual Machine
x.gc(); // runs garbage collector
//x.exit(1); // terminates the currently running Java Virtual Machine
x.runFinalization(); // runs the finalization methods of any objects pending finalization
//%2 x.runFinalizersOnExit(true); // enable or disable finalization on exit
//try {
// Process p = x.exec("winmine"); // executes string command in separate process
//} catch(java.io.IOException e) {
//}
/* TO BE DETERMINED
load(String) // loads the specified filename as a dynamic library
loadLibrary(String) // loads the dynamic library with the specified library name
traceInstructions(boolean) // enables/disables tracing of instructions
traceMethodCalls(boolean) // enables/disables tracing of method calls
*/
}
/*********************************************************************
* *
* Process: used to control and obtain info about process *
* *
* destroy getErrorStream getOutputStream *
* exitValue getInputStream waitFor *
* *
*********************************************************************/
private void process() {
int i;
java.io.InputStream in;
java.io.InputStream err;
java.io.OutputStream out;
try {
Process p = Runtime.getRuntime().exec("winmine");
in = p.getInputStream(); // gets input stream of the subprocess
err = p.getErrorStream(); // gets error stream of the subprocess
out = p.getOutputStream(); // gets output stream of the subprocess
p.destroy(); // kills the subprocess
i = p.waitFor(); // waits for subprocess to complete
i = p.exitValue(); // returns exit value for the subprocess
} catch(java.io.IOException e) {
} catch(InterruptedException e) {
System.out.println(e);
}
}
/*********************************************************************
* *
* SecurityManager: implement security policy (abstract) *
* *
* checkAccept checkRead *
* checkAccess checkSecurityAccess *
* checkAwtEventQueueAccess checkSetFactory *
* checkConnect checkSystemClipboardAccess *
* checkCreateClassLoader checkTopLevelWindow *
* checkDelete checkWrite *
* checkExec classDepth *
* checkExit %classLoaderDepth *
* checkLink %currentClassLoader *
* checkListen %currentLoadedClass *
* checkMemberAccess getClassContext *
* checkMulticast %getInCheck *
* checkPermission getSecurityContext *
* checkPackageAccess getThreadGroup *
* checkPackageDefinition %inCheck *
* checkPrintJobAccess %inClass *
* checkPropertiesAccess %inClassLoader *
* checkPropertyAccess *
* *
*********************************************************************/
class cmrSecurityManager extends SecurityManager {
public cmrSecurityManager() {
int i;
boolean b;
String cn = "Test.Chris.Java_lang$cmrSecurityManager";
Class[] cx;
ClassLoader cl;
Class c;
cx = getClassContext(); // classes on the stack - see who called us
for (i = 0; i < cx.length; i++) {
String s = cx[i].getName();
}
//!2 cl = currentClassLoader(); // most recent class loader
//!2 c = currentLoadedClass(); // class most recently loaded from class loader
//!2 i = classLoaderDepth(); // call stack depth of class most recently loaded from class loader
//!2 i = classDepth(cn); // call stack depth of given class
//!2 b = inClass(cn); // test if class in stack
//!2 b = inClassLoader(); // test if any class on stack came from class loader
}
// tests if calling thread is permitted to accept a socket connection from specified host/port number
public void checkAccept(String host, int port) { /* sockets */
System.out.println("SecurityManager.checkAccept");
if (host == null) throw new NullPointerException("host cant be null");
checkPermission(new java.net.SocketPermission(host + ":" + port, "accept"));
}
// tests if calling thread is allowed to modify the thread argument
private RuntimePermission threadPermission;
private ThreadGroup rootGroup = getRootGroup();
private ThreadGroup getRootGroup() {
ThreadGroup root = Thread.currentThread().getThreadGroup();
while (root.getParent() != null) root = root.getParent();
return root;
}
public void checkAccess(Thread t) { /* threads */
if (t.getThreadGroup() != rootGroup) return;
if (threadPermission == null)
threadPermission = new RuntimePermission("modifyThread");
checkPermission(threadPermission);
}
// tests if calling thread is allowed to modify the thread group argument
private RuntimePermission threadGroupPermission;
public void checkAccess(ThreadGroup g) { /* threads */
if (g == null) throw new NullPointerException("thread group can't be null");
if (g != rootGroup) return;
if (threadGroupPermission == null)
threadGroupPermission = new RuntimePermission("modifyThreadGroup");
checkPermission(threadGroupPermission);
}
// tests if a client can get access to the AWT event queue
private java.awt.AWTPermission checkAwtEventQueuePermission;
public void checkAwtEventQueueAccess() {
if (checkAwtEventQueuePermission == null)
checkAwtEventQueuePermission = new java.awt.AWTPermission("accessEventQueue");
checkPermission(checkAwtEventQueuePermission);
}
// tests if calling thread is allowed to open a socket connection to specified host and port number
public void checkConnect(String host, int port) { /* sockets */
if (host == null) throw new NullPointerException("host can't be null");
if (port == -1) {
checkPermission(new java.net.SocketPermission(host, "resolve"));
} else {
checkPermission(new java.net.SocketPermission(host + ":" + port, "connect"));
}
}
// tests if specified security context is allowed to open socket connection to specified host/port num
public void checkConnect(String s, int i, Object x) { /* sockets */
System.out.println("SecurityManager.checkConnect");
// throw new SecurityException("checkConnect: " + s + ":" + i + ":" + x);
}
// tests if calling thread is allowed to create new class loader
public void checkCreateClassLoader() { /* class loader */
//throw new SecurityException("createClassLoader");
}
// tests if calling thread is allowed to delete specified file
public void checkDelete(String s) { /* file system */
// throw new SecurityException("checkDelete: " + s);
}
// tests if calling thread is allowed to create subprocess
public void checkExec(String s) { /* system commands */
// throw new SecurityException("checkExec: " + s);
}
// tests if calling thread is allowed to cause the JVM to halt with specified status code
public void checkExit(int i) { /* interpreter */
// throw new SecurityException("checkExit: " + i);
}
// tests if calling thread is allowed to dynamic link library code specified by string argument file
public void checkLink(String s) { /* file system */
// throw new SecurityException("checkLink: " + s);
}
// tests if calling thread is allowed to wait for connection request on specified local port number
public void checkListen(int i) { /* sockets */
System.out.println("SecurityManager.checkListen");
// throw new SecurityException("checkListen: " + i);
}
// tests if a client is allowed to access members
public void checkMemberAccess(Class c, int i) {
// throw new SecurityException("checkMemberAccess: " + c + ":" + i);
}
// tests if current execution context is allowed to use (join/leave/send/receive) IP multicast
public void checkMulticast(java.net.InetAddress a) {
System.out.println("SecurityManager.checkMulticast0");
// throw new SecurityException("checkMulticast: " + a);
}
// tests to see if current execution context is allowed to use (join/leave/send/receive) IP multicast
public void checkMulticast(java.net.InetAddress a, byte b) {
System.out.println("SecurityManager.checkMulticast1");
// throw new SecurityException("checkMulticast: " + a + ":" + b);
}
// tests if calling thread is allowed to access the package specified by the argument
public void checkPackageAccess(String s) { /* package */
// throw new SecurityException("checkPackageAccess: " + s);
}
// tests if calling thread is allowed to define classes in the package specified by the argument
public void checkPackageDefinition(String s) { /* package */
System.out.println("SecurityManager.checkPackageDefinition");
// throw new SecurityException("checkPackageDefinition: " + s);
}
// tests if a client can initiate a print job request
public void checkPrintJobAccess() {
System.out.println("SecurityManager.checkPrintJobAccess");
// throw new SecurityException("checkPrintJobAccess");
}
// tests if calling thread is allowed to access or modify the system properties
public void checkPropertiesAccess() { /* properties */
// throw new SecurityException("checkPropertiesAccess:");
}
// tests if calling thread is allowed to access the system property with the specified key name
public void checkPropertyAccess(String key) { /* properties */
checkPermission(new java.util.PropertyPermission(key, "read"));
// throw new SecurityException("PropertyAccess: " + key);
}
// tests if calling thread is allowed to read from the specified file descriptor
public void checkRead(java.io.FileDescriptor fd) { /* file system */
// throw new SecurityException("checkRead:0 " + fd);
}
// tests if calling thread is allowed to read file specified
public void checkRead(String s) { /* file system */
if (!s.endsWith("java")) {
// throw new SecurityException("Access to file not allowed: " + s);
}
}
// tests if specified security context is allowed to read the file specified by the string argument
public void checkRead(String s, Object x) { /* file system */
System.out.println("SecurityManager.checkRead2");
// throw new SecurityException("checkRead:2 " + s + ":" + x);
}
// tests access to certain operations for a security API action
public void checkSecurityAccess(String s) {
System.out.println("SecurityManager.checkSecurityAccess");
// throw new SecurityException("checkSecurityAccess: " + s);
}
// tests if calling thread is allowed to set the socket factory used by ServerSocket or Socket,
// or the stream handler factory used by URL
public void checkSetFactory() { /* networking */
System.out.println("SecurityManager.checkSetFactory");
// throw new SecurityException("checkSetFactory");
}
// tests if a client can get access to the system clipboard
public void checkSystemClipboardAccess() {
System.out.println("SecurityManager.checkSystemClipboardAccess");
// throw new SecurityException("checkSystemClipboardAccess");
}
// tests if calling thread is trusted to bring up the top-level window indicated by the window argument
public boolean checkTopLevelWindow(Object x) { /* windows */
return true;
}
// tests if calling thread is allowed to write to the specified file descriptor
public void checkWrite(java.io.FileDescriptor fd) { /* file system */
// throw new SecurityException("checkWrite:0 " + fd);
}
// tests if calling thread is allowed to write to the file specified by the string argument
public void checkWrite(String s) { /* file system */
// throw new SecurityException("checkWrite:1 " + s);
}
// tests if requested access, specified by the given permission, is permitted (jdk2)
public void checkPermission(java.security.Permission p) {
// throw new SecurityException("checkPermission:1 " + p);
}
// tests if requested access to specific resource, specified by the given permission, is permitted (jdk2)
public void checkPermission(java.security.Permission p, Object context) {
System.out.println("SecurityManager.checkPerssion(2)");
// throw new SecurityException("checkWrite:1 " + s);
}
}
private void securitymanager() {
boolean b;
Object d;
ThreadGroup t;
cmrSecurityManager x = new cmrSecurityManager();
System.setSecurityManager(x); // sets the System security
//!2 b = x.getInCheck(); // tests if there is a security check in progress
d = x.getSecurityContext(); // creates an object that encapsulates current execution environment
t = x.getThreadGroup(); // returns thread group into which to instantiate any new thread
}
/*********************************************************************
* *
* #RuntimePermission: represents permission for operations *
* *
*********************************************************************/
private void runtimepermission() {
RuntimePermission r;
r = new RuntimePermission("createClassLoader");
r = new RuntimePermission("getClassLoader");
r = new RuntimePermission("setContextClassLoader");
r = new RuntimePermission("setSecurityManager");
r = new RuntimePermission("createSecurityManager");
r = new RuntimePermission("exitVM");
r = new RuntimePermission("setFactory");
r = new RuntimePermission("setIO");
r = new RuntimePermission("modifyThread");
r = new RuntimePermission("stopThread");
r = new RuntimePermission("modifyThreadGroup");
r = new RuntimePermission("getProtectionDomain");
r = new RuntimePermission("readFileDescriptor");
r = new RuntimePermission("writeFileDescriptor");
r = new RuntimePermission("loadLibrary.{windows.*}");
r = new RuntimePermission("accessClassInPackage.{Test.Chris.*}");
r = new RuntimePermission("defineClassInPackage.{Test.Chris.*}");
r = new RuntimePermission("accessDeclaredMembers");
r = new RuntimePermission("queuePrintJob");
}
/*********************************************************************
* *
* Object: root of the class hierarchy *
* *
* clone getClass notifyAll *
* equals hashCode toString *
* finalize notify wait *
* *
*********************************************************************/
private void object() {
boolean f;
Object x = new String("ABC");
String y = (String)x;
f = x.equals(y); // compares two Objects for equality
Class c = x.getClass(); // returns the runtime class of an object
int i = x.hashCode(); // returns a hash code value for the object
y = x.toString(); // returns a string representation of the object
testNotify z = new testNotify();
synchronized(z) {
new Thread(z).start();
try {
z.wait(1000); // waits to be notified by another thread of a change in this object
} catch(InterruptedException e) {
}
}
}
class testNotify implements Runnable {
public void run() {
synchronized(this) {
// notify(); // wakes up a single thread that is waiting on this object's monitor
notifyAll(); // wakes up all threads that are waiting on this object's monitor
}
}
}
/*********************************************************************
* *
* #Comparable: imposes total ordering on the objects (Interface) *
* *
* compareTo *
* *
*********************************************************************/
class cmrComparable implements Comparable {
public int value = 0;
cmrComparable(int i) {
value = i;
}
public int compareTo(java.lang.Object x) {
return 0;
}
}
private void comparable() {
cmrComparable x = new cmrComparable(100);
cmrComparable y = new cmrComparable(200);
int i = x.compareTo(y); // compares this object with the specified object for order
}
/*********************************************************************
* *
* Cloneable: allow field-for-field copy (Interface) *
* *
* A class implements the Cloneable interface to indicate to the *
* clone method in class Object that it is legal for that method *
* to make a field-for-field copy of instances of that class. *
* Attempts to clone instances that do not implement the Cloneable*
* interface result in the exception CloneNotSupportedException *
* being thrown. *
* *
*********************************************************************/
class cmrCloneable implements Cloneable {
String s;
public Object clone() {
cmrCloneable y = new cmrCloneable();
y.s = new String(s);
return y;
}
}
private void cloneable() {
cmrCloneable x = new cmrCloneable();
x.s = "Hello";
cmrCloneable y = (cmrCloneable)x.clone();
}
/*********************************************************************
* *
* #Package: info about class package *
* *
* getImplementationTitle getSpecificationVendor *
* getImplementationVendor getSpecificationVersion *
* getImplementationVersion hashCode *
* getName isCompatibleWith *
* getPackage isSealed *
* getPackages toString *
* getSpecificationTitle *
* *
*********************************************************************/
private void packages() {
boolean b;
int i;
String s;
Package p = Integer.class.getPackage();
Package[] q;
s = p.getImplementationTitle(); // title of package
s = p.getImplementationVendor(); // name of vendor
s = p.getImplementationVersion(); // version of implementation
s = p.getName(); // name of this package
s = p.getSpecificationTitle(); // title of the specification that package implements
s = p.getSpecificationVendor(); // name of vendorowns and maintains the specification
s = p.getSpecificationVersion(); // version number of the specification
i = p.hashCode(); // hashcode computed from the package name
s = p.toString(); // string representation
b = p.isCompatibleWith("1.2.0"); // compare specification version with desired version
b = p.isSealed(); // test if package is sealed
try {
java.net.URL url = new java.net.URL("http://rhcus/index.html");
b = p.isSealed(url); // test if package is sealed with respect to url
} catch(java.net.MalformedURLException e) {
}
p = Package.getPackage("java.io");// Find package by name in callers classloader
q = Package.getPackages(); // Get all the packages currently known for the caller's class loader
}
/*********************************************************************
* *
* Class: classes and interfaces in a running Java app *
* *
* forName getInterfaces *
* getClasses getMethod *
* getClassLoader getMethods *
* getComponentType getModifiers *
* getConstructor getName *
* getConstructors getResource *
* getDeclaredClasses getResourceAsStream *
* getDeclaredConstructor getSigners *
* getDeclaredConstructors getSuperclass *
* getDeclaredField isArray *
* getDeclaredFields isAssignableFrom *
* getDeclaredMethod isInstance *
* getDeclaredMethods isInterface *
* getDeclaringClass isPrimitive *
* getField newInstance *
* getFields toString *
* *
* #getPackage #getProtectionDomain *
* *
*********************************************************************/
private void classes() {
boolean b;
String s;
Long i = new Long(1234);
Long j;
Class c;
Class d;
Class[] dx;
java.lang.reflect.Field fx;
java.lang.reflect.Method mx;
java.lang.reflect.Constructor cx;
java.lang.reflect.Field[] fa;
java.lang.reflect.Method[] ma;
java.lang.reflect.Constructor[] ca;
Package p;
c = i.getClass(); // method of object class
c = Long.class; // can get class statically
s = c.getName(); // name of type (class, interface, array, or primitive)
try {
c = String.class;
s = (String)c.newInstance(); // creates a new instance of a class
} catch(IllegalAccessException e) {
} catch(InstantiationException e) {
}
try {
c = Class.forName("java.lang.Long"); // returns Class object associated with the class
} catch(ClassNotFoundException e) {
}
d = Double.class;
b = c.isAssignableFrom(d); // class/interface is same or superclass
b = c.isInstance(s); // dynamic equivalent of instanceof operator
b = c.isInterface(); // test if an interface type
b = c.isPrimitive(); // test if primitive Java type
b = c.isArray(); // test if an array type
s = c.toString(); // converts to a string
c = Double.class;
fa = c.getFields(); // all public fields of the class
for (int k = 0; k < fa.length; k++) {
s = fa[k].toString();
}
fa = c.getDeclaredFields(); // all fields declared by the class
for (int k = 0; k < fa.length; k++) {
s = fa[k].toString();
}
try {
fx = c.getField("MIN_VALUE"); // reflects the specified public field
fx = c.getDeclaredField("MAX_VALUE"); // reflects the specified declared field
} catch(NoSuchFieldException e) {
}
ma = c.getMethods(); // public member methods of the class
for (int k = 0; k < ma.length; k++) {
s = ma[k].toString();
}
ma = c.getDeclaredMethods(); // all methods declared by the class
for (int k = 0; k < ma.length; k++) {
s = ma[k].toString();
}
try {
mx = c.getMethod("toString", new Class[] {}); // reflects a public method
mx = c.getDeclaredMethod("hashCode", new Class[] {}); // reflects a declared method
} catch(NoSuchMethodException e) {
}
ca = c.getConstructors(); // all public constructors of the class
for (int k = 0; k < ca.length; k++) {
s = ca[k].toString();
}
ca = c.getDeclaredConstructors(); // all constructors declared by class
for (int k = 0; k < ca.length; k++) {
s = ca[k].toString();
}
try {
cx = c.getConstructor(new Class[] { String.class }); // reflects the public constructor
cx = c.getDeclaredConstructor(new Class[] { double.class }); // reflects the declared constructor
} catch(NoSuchMethodException e) {
}
d = c.getSuperclass(); // superclass of the class
d = c.getDeclaringClass(); // class of the outerclass (for an innerclass)
dx = c.getInterfaces(); // interfaces implemented (or name of interface)
for (int k = 0; k < dx.length; k++) {
s = dx[k].toString();
}
d = dx.getClass().getComponentType(); // array component type
int k = c.getModifiers(); // Java language modifiers (encoded in an integer)
Object[] sa = c.getSigners(); // get signers of this class (native)
ClassLoader cl = c.getClassLoader(); // determines the class loader for the class
p = Integer.class.getPackage(); // gets package for this class
/* TO BE DETERMINED
getClasses() // Returns array containing Class objects representing all the
// public classes and interfaces that are members of the class
// represented by this Class object
getDeclaredClasses() // Returns array of Class objects reflecting all the classes and
// interfaces declared as members of the class represented by this
// Class object
getResource(String) // Finds resource with the specified name
getResourceAsStream(String) // Finds resource with a given name
ProtectionDomain getProtectionDomain() // protectionDomain of this class
*/
}
/*********************************************************************
* *
* ClassLoader: class loader *
* *
* defineClass getSystemResource *
* findLoadedClass getSystemResourceAsStream *
* findSystemClass loadClass *
* getResource resolveClass *
* getResourceAsStream setSigners *
* *
* #definePackage #getPackage *
* #findClass #getPackages *
* #findLibrary #getParent *
* #findResource #getResources *
* #findResources #getSystemClassLoader *
* *
*********************************************************************/
class CMRClassLoader extends ClassLoader {
java.util.Hashtable classCache = new java.util.Hashtable();
protected Class loadClass(String classLoc, boolean resolve) throws ClassNotFoundException {
int i;
Class c = null;
String className;
String name;
java.io.File file;
java.io.DataInputStream ios;
className = classLoc;
name = "TestClass";
// check if we have already loaded class
c = (Class)classCache.get(className);
if (c != null) return c;
// check if loaded by default loader
c = super.findLoadedClass(className); // find loaded class
if (c != null) return c;
// check if this is a system class
try {
c = super.findSystemClass(className); // find-load system class
return c;
} catch(ClassNotFoundException e) {
}
// not found - load it from stream
try {
file = new java.io.File(className);
i = (int)file.length();
byte[] b = new byte[i];
ios = new java.io.DataInputStream(new java.io.FileInputStream(className));
ios.readFully(b);
c = defineClass(name, b, 0, i); // converts array of bytes to an instance of class Class
} catch(java.io.IOException e) {
throw new ClassNotFoundException("IOException in loading class");
} catch(ClassFormatError e) {
throw new ClassNotFoundException("ClassFormatError in loading class");
}
classCache.put(className, c);
if (resolve) resolveClass(c); // resolves class so that it can be instanciated
return c;
}
}
private void classloader() {
Integer n;
Class c;
Object x;
Object[] ox;
java.lang.reflect.Constructor mx;
java.lang.reflect.Method fx;
CMRClassLoader cldr = new CMRClassLoader();
try {
c = cldr.loadClass("TestClass.class"); // requests class loader to load/resolve class
mx = c.getConstructor(null);
x = mx.newInstance(null);
ox = new Object[1];
ox[0] = new Integer(1234);
fx = c.getMethod("testClassMethod", new Class[] {int.class});
n = (Integer)fx.invoke(x, ox);
} catch(ClassNotFoundException e) {
} catch(IllegalAccessException e) {
} catch(InstantiationException e) {
} catch(NoSuchMethodException e) {
} catch(java.lang.reflect.InvocationTargetException e) {
}
/* TO BE DETERMINED
getResource(String) // find a resource with a given name
getResourceAsStream(String) // get an InputStream on a given resource
getSystemResource(String) // find a resource with a given name
getSystemResourceAsStream(String) // get an InputStream on a given resource.
setSigners(Class, Object[]) // sets the signers of a class
Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) // Defines a package by name in this ClassLoader
Class findClass(String name) // Finds specified class
String findLibrary(String libname) // Returns the absolute path name of a native library
URL findResource(String name) // Finds the resource with the given name
Enumeration findResources(String name) // Returns an Enumeration of URLs representing all the resources with the given name
Package getPackage(String name) // Returns a Package that has been defined by this class loader or any of its ancestors.
Package[] getPackages() // Returns all of the Packages defined by this class loader and its ancestors.
ClassLoader getParent() // Returns the parent class loader for delegation
Enumeration getResources(String name) // Finds all the resources with the given name.
static ClassLoader getSystemClassLoader() // Returns the system class loader for delegation
static Enumeration getSystemResources(String name) // Finds all resources of the specified name from the search path used to load classes
*/
}
/*********************************************************************
* *
* Compiler: support for Java-to-native-code compilers *
* *
* command compileClasses enable *
* compileClass disable *
* *
*********************************************************************/
private void compiler() {
// all methods are static - no constructor
Compiler.disable(); // Cause the Compiler to cease operation
Compiler.enable(); // Cause the Compiler to resume operation
// System.loadLibrary("symcjit");
/* TO BE DETERMINED
boolean b = Compiler.compileClasses("Test.Chris.");
System.out.println(b);
command(Object) // Examines the argument type and its fields and perform some documented operation
compileClass(Class) // Compiles the specified class
compileClasses(String) // Compiles all classes whose name matches the specified string
*/
}
/*********************************************************************
* *
* Runnable: thread execution support (Interface) *
* *
* run *
* *
* When an object implementing interface Runnable is used to *
* create a thread, starting the thread causes the object's *
* run method to be called in that separately executing thread *
*********************************************************************/
class runCMR implements Runnable {
public void run() {
}
}
private void runnable() {
runCMR x = new runCMR();
Thread y = new Thread(x);
y.start();
}
/*********************************************************************
* *
* Thread: a thread of execution in a program *
* *
* MAX_PRIORITY MIN_PRIORITY NORM_PRIORITY *
* *
* activeCount getThreadGroup setDaemon *
* checkAccess interrupt setName *
* %countStackFrames interrupted setPriority *
* currentThread isAlive sleep *
* destroy isDaemon start *
* dumpStack isInterrupted %stop *
* enumerate join %suspend *
* getName %resume toString *
* getPriority run yield *
* *
* #getContextClassLoader #setContextClassLoader *
* *
*********************************************************************/
class ChrisThread extends Thread {
String tname;
public ChrisThread(String tname) {
this.tname = tname;
}
public void run() {
for (int i = 0; i < 4; i++) {
try {
yield();
sleep(200);
} catch(InterruptedException e) {
}
}
}
}
class ChrisRunnable implements Runnable {
public ChrisRunnable() {
}
public void run() {
for (int i = 0; i < 4; i++) {
testsync();
Thread.yield();
synchronized(this) {
// System.out.println("BlockThreadIn = " + Thread.currentThread().getName());
try {
Thread.sleep(500);
} catch(InterruptedException e) {
}
// System.out.println("BlockThreadOut = " + Thread.currentThread().getName());
}
}
}
synchronized private void testsync() {
// System.out.println("ThreadIn = " + Thread.currentThread().getName());
try {
Thread.sleep(500);
} catch(InterruptedException e) {
}
// System.out.println("ThreadOut = " + Thread.currentThread().getName());
}
}
private void thread() {
int i;
int j;
boolean b;
String s;
Thread xa;
Thread[] xb;
ThreadGroup xc;
Thread x = new ChrisThread("X");
ChrisRunnable xd = new ChrisRunnable();
Thread y = new Thread((Runnable)xd);
Thread z = new Thread((Runnable)xd, "Z Thread");
xa = Thread.currentThread(); // returns a reference to the currently executing thread object
s = xa.getName();
j = Thread.activeCount(); // current number of active threads in this thread group
xb = new Thread[j];
j = Thread.enumerate(xb); // every active thread in this thread group and its subgroups
for (i = 0; i < j; i++) {
s = xb[i].getName();
}
xc = x.getThreadGroup(); // returns this thread's thread group
try {
x.checkAccess(); // determine if have permission to modify this thread
} catch(SecurityException e) {
}
x.setName("X Thread"); // changes the name of this thread to be equal to the argument name
y.setName("Y Thread");
s = x.getName(); // returns this thread's name
x.setPriority(x.MAX_PRIORITY); // changes priority of thread
y.setPriority(y.MIN_PRIORITY);
z.setPriority(z.NORM_PRIORITY);
i = x.getPriority(); // returns thread priority
y.setDaemon(true); // marks this thread as either a daemon thread or a user thread
b = y.isDaemon(); // tests if this thread is a daemon thread
x.start(); // causes this thread to begin execution
y.start();
z.start();
x.interrupt(); // interrupts this thread
b = x.interrupted(); // tests if the current thread has been interrupted
b = x.isInterrupted(); // tests if the current thread has been interrupted
//%2 x.suspend(); // suspends this thread
//%2 x.resume(); // resumes a suspended thread
b = x.isAlive(); // tests if this thread is alive
//%2 i = x.countStackFrames(); // counts the number of stack frames in this thread
Thread.yield(); // temporarily pause and allow other threads to execute
try {
Thread.sleep(500); // causes thread to sleep (milliseconds)
} catch(InterruptedException e) {
}
try {
x.join(500); // waits at most millis milliseconds[, nanosecs] for thread to die
y.join(); // waits for this thread to die
} catch(InterruptedException e) {
Thread.dumpStack(); // prints a stack trace of the current thread (debug)
}
x.run(); // runnable object's run method is called
//%2 y.stop(); // forces thread to stop executing
try {
y.destroy(); // destroys this thread, without any cleanup (not implemented yet)
} catch(NoSuchMethodError e) {
}
s = x.toString(); // returns a string representation of this thread
/* TO BE DETERMINED
ClassLoader getContextClassLoader() // Returns the context ClassLoader for this Thread
void setContextClassLoader(ClassLoader cl) // Sets the context ClassLoader for this Thread
*/
}
/*********************************************************************
* *
* ThreadGroup: a set of threads *
* *
* activeCount isDestroyed *
* activeGroupCount list *
* %allowThreadSuspension parentOf *
* checkAccess %resume *
* destroy setDaemon *
* enumerate setMaxPriority *
* getMaxPriority %stop *
* getName %suspend *
* getParent toString *
* isDaemon uncaughtException *
* *
* #interrupt *
* *
*********************************************************************/
class CMRRunnable implements Runnable {
public void run() {
while (true) {
// System.out.println("BlockThreadIn = " + Thread.currentThread().getName());
try {
Thread.sleep(500);
} catch(InterruptedException e) {
}
}
}
}
private void threadgroup() {
int i;
boolean f;
String s;
CMRRunnable x = new CMRRunnable();
CMRRunnable y = new CMRRunnable();
CMRRunnable z = new CMRRunnable();
ThreadGroup xc;
ThreadGroup xd;
xc = new ThreadGroup("CMRThreadGroup");
s = xc.getName(); // returns the name of this thread group
xd = xc.getParent(); // returns the parent of this thread group
s = xc.toString(); // returns a string representation of this Thread group
// xc.list(); // prints info about this thread group to the standard output
i = xc.getMaxPriority(); // returns the maximum priority of this thread group
xc.setMaxPriority(i-2); // sets the maximum priority of the group
xc.setDaemon(true); // changes the daemon status of this thread group
f = xc.isDaemon(); // tests if this thread group is a daemon thread group
f = xc.isDestroyed(); // tests if this thread group has been destroyed
f = xd.parentOf(xc); // tests if same group or one of its ancestor thread groups
//%2 f = xc.allowThreadSuspension(true); // used by VM to control lowmem implicit suspension
try {
xc.checkAccess(); // tests if current thread has permission to modify thread group
} catch(SecurityException e) {
}
Thread xx = new Thread(xc, (Runnable)x, "X");
Thread xy = new Thread(xc, (Runnable)x, "Y");
Thread xz = new Thread(xc, (Runnable)x, "Z");
xx.start();
xy.start();
xz.start();
try {
Thread.sleep(1500);
} catch(InterruptedException e) {
}
i = xc.activeCount(); // returns estimate of number of active threads in this thread group
i = xd.activeGroupCount(); // returns estimate of number of active groups in this thread group
Thread[] tx = new Thread[xc.activeCount()];
xc.enumerate(tx, true); // get all threads in thread group - with recursion
for (i = 0; i < tx.length; i++) {
s = tx[i].toString();
}
ThreadGroup[] gx = new ThreadGroup[xd.activeGroupCount()];
xd.enumerate(gx, true); // get all thread groups in thread group - with recursion
for (i = 0; i < gx.length; i++) {
s = gx[i].toString();
}
//%2 xc.suspend(); // suspends all processes in this thread group
//%2 xc.resume(); // resumes all processes in this thread group
//%2 xc.stop(); // stops all processes in this thread group
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
}
// xc.destroy(); // destroys this thread group and all of its subgroups
/* TO BE DETERMINED
uncaughtException(Thread, Throwable) // called by the JVM when thread stops on an uncaught exception
void interrupt() // Interrupts all threads in this thread group
*/
}
/*********************************************************************
* *
* #ThreadLocal: provides ThreadLocal variables *
* *
* get ^initialValue set *
* *
*********************************************************************/
private void threadlocal() {
Object x = new Object();
ThreadLocal t = new ThreadLocal();
t.set(x); // sets ThreadLocal variable to the given value
x = t.get(); // value in ThreadLocal variable
}
/*********************************************************************
* *
* #InheritableThreadLocal: inherit values from parent to child *
* *
* ^childValue *
* *
*********************************************************************/
private void inheritablethreadlocal() {
Object x = new Object();
InheritableThreadLocal t = new InheritableThreadLocal();
t.set(x);
x = t.get();
/* TO BE DETERMINED
x = childValue(x); // computes child's initial value at time child Thread is created
*/
}
/*********************************************************************
* *
* Throwable: superclass of all errors and exceptions *
* *
* fillInStackTrace getMessage toString *
* getLocalizedMessage printStackTrace *
* *
*********************************************************************/
class MyException extends Throwable {
MyException() {
}
MyException(String s) {
super(s);
}
}
class testException {
public void testme() throws MyException {
throw new MyException("MyException");
}
}
private void throwable() {
String s;
testException x = new testException();
try {
x.testme();
} catch(MyException e) {
s = e.getMessage(); // returns the detail message of this throwable object
s = e.getLocalizedMessage(); // creates a localized description of this Throwable
s = e.toString(); // returns a short description of this throwable object
// e.printStackTrace(); // prints this Throwable and its backtrace to standard error stream
}
/* TO BE DETERMINED
throw e.fillInStackTrace(); // fills in the execution stack trace - useful for re-throw
*/
}
}