This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
/** Demonstrate deprecation warning */ | |
public class Deprec { | |
public static void main(String[] av) { | |
// Create a Date object for May 5, 1986 | |
// EXPECT DEPRECATION WARNING | |
Date d = new Date(86, 04, 05); // May 5, 1986 | |
System.out.println("Date is " + d); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** This program exhibits some bugs, so we can use a debugger */ | |
public class Buggy { | |
static String name; | |
public static void main(String[] args) { | |
int n = name.length( ); // bug # 1 | |
System.out.println(n); | |
name += "; The end."; // bug #2 | |
System.out.println(name); // #3 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** A simple class used to demonstrate unit testing. */ | |
public class Person { | |
protected String fullName; | |
protected String firstName, lastName; | |
/** Construct a Person using his/her first+last names. */ | |
public Person(String firstName, String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
/** Get the person's full name */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.darwinsys.util; | |
/** Utilities for debugging | |
*/ | |
public class Debug { | |
/** Static method to see if a given category of debugging is enabled. | |
* Enable by setting e.g., -Ddebug.fileio to debug file I/O operations. | |
* Use like this:<BR> | |
* if (Debug.isEnabled("fileio"))<BR> | |
* System.out.println("Starting to read file " + fileName); | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return the nth ancestor of e, or null if there is no such ancestor | |
* or if that ancestor is not an Element (a Document or DocumentFragment e.g.). | |
* If n is 0 return e itself. If n is 1 (or | |
* omitted) return the parent. If n is 2, return the grandparent, etc. | |
*/ | |
function parent(e, n) { | |
if (n === undefined) n = 1; | |
while(n-- && e) e = e.parentNode; | |
if (!e || e.nodeType !== 1) return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.darwinsys.util.GetOpt; | |
/** Trivial demonstration of GetOpt. If -h present, print help. | |
*/ | |
public class GetOptSimple { | |
public static void main(String[] args) { | |
GetOpt go = new GetOpt("h"); | |
char c; | |
while ((c = go.getopt(args)) !=GetOpt.DONE) { | |
switch(c) { | |
case 'h': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.darwinsys.lang; | |
import com.darwinsys.util.Debug; | |
import java.util.Map; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
/** A class to implement Unix-style (single-character) command-line argument | |
* parsing. Originally patterned after (but not using code from) the Unix | |
* getopt(3) program, this has been redesigned to be more Java-friendly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Test for JDK >= 1.1 */ | |
public class TestJDK11 { | |
public static void main(String[] a) { | |
// Check for JDK >= 1.1 | |
try { | |
Class.forName("java.lang.reflect.Constructor"); | |
} catch (ClassNotFoundException e) { | |
String failure = | |
"Sorry, but this version of MyApp needs \n" + | |
"a Java Runtime based on Java JDK 1.1 or later"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
/** Show using a StringTokenizer including getting the delimiters back */ | |
public class StrTokDemo4 { | |
public final static int MAXFIELDS = 5; | |
public final static String DELIM = "|"; | |
/** Processes one String; returns it as an array of Strings */ | |
public static String[] process(String line) { | |
String[] results = new String[MAXFIELDS]; | |
// Unless you ask StringTokenizer to give you the tokens, | |
// it silently discards multiple null tokens. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* StringBufferDemo: construct the same String three different ways. | |
*/ | |
public class StringBufferDemo { | |
public static void main(String[] argv) { | |
String s1 = "Hello" + ", " + "World"; | |
System.out.println(s1); | |
// Build a StringBuffer, and append some things to it. | |
StringBuffer sb2 = new StringBuffer( ); | |
sb2.append("Hello"); |