//============================================
System.err.println("This goes to the screen");
FileOutputStream errFile = new FileOutputStream("err.log");
System.err = new PrintStream(errFile, true);
System.err.println("This goes to err.log file");
//============================================
//============================================
System.out.print(...)
System.out.println(...)
//============================================
Almost anything can be placed
as argument for these print functions. In particular, every
object x has a "print value", which is a String:
this is simply obtained by the x.toString() method available
with all objects. Useful note: you can concatenate these
print values by "+". E.g. System.out.print("n = " + n);
//========================================================
DataInputStream r = new DataInputStream(); // by default, r
// is attached to System.in. If you want to read
// from a file named "foo.txt", then say instead:
// new DataInputStream(new FileInputStream("foo.txt"))
int i;
for (r.skipWhite(); !r.eof(); r.skipWhite())
{ i = r.readInt();
System.out.println(i);
}
r.close();
Other methods:
r.readChar() -- returns next char
r.readBoolean()
r.readLong()
r.readFloat()
r.readDouble()
r.readString()
r.readLine() -- returns String
r.readln() -- returns void
r.eof() -- returns true if no more data in r
r.eoln() -- returns true if no more data in line
//=========================================================
To make the default input for ReadStream to be XXX, say
ReadStream.setIn(XXX) where XXX is a InputStream.
//=====================================
class C1 {
// member variables
int myName;
// constructors
C1(int n) {...}
// methods
public void doThis() {...}
}
//=====================================
//=====================================
C1 C1object;
C1object = new C1(5);
//=====================================
//=====================================
class C2 extends C1 {...}
//=====================================
//=====================================
interface LIST {
...
}
class MyList implements LIST {
...
}
class AugList extends MyList implements LIST {
...
}
//=====================================
//=====================================
char c[] = {'a', '1', 'b', '2'};
String s = new String(c); // s = "a1b2"
//=====================================
//=====================================
String s = "do" // s = "do"
String ss = s + s; // ss = "dodo"
//=====================================
//=====================================
String s = "good"; // instantiation
int i = s.length; // i = 4
boolean b = s.equals("GOOD"); // b=false
b = s.equalsIgnoreCase("GOOD"); // b=true
i = s.indexOf('o'); // i=1 (first occurrence)
i = s.lastIndexOf('o'); // i=2 (last occurrence)
i = s.indexOf("od"); // i=2
String t = s.substring(2); // t="od"
String tt = s.substring(0,2); // t="go"
String u = s.concat(" work"); // u="good work"
//=====================================
//=====================================
int x[] = new int[50]; // array of 50 ints
public int table()[]; // table() returns an int array
//=====================================
//=====================================
int[] x = new int[50];
public int[] table(); // looks neater!
//=====================================
//=====================================
char[] c = {'a', 'b', 'c'};
int[] x = {1,2,3};
//=====================================
//=====================================
char student[][] = new char[10][30]; // each sublist of length 30
int varLists[][] = new int[3][];
varLists[0] = new int[10]; // each sublist has different
varLists[1] = new int[20]; // lengths!
varLists[2] = new int[5];
//=====================================