import java.io.*;
class LowerCaseReader extends FilterReader {
public LowerCaseReader(Reader in) {
super(in);
}
public int read()
throws IOException
{
int c = in.read();
if (c >= 0)
c = Character.toLowerCase((char) c);
return c;
}
public int read(char buf[], int off, int len)
throws IOException
{
int nRead = in.read(buf, off, len);
if (nRead > 0)
for (int i = off; i < off + nRead; i++)
buf[i] = Character.toLowerCase(buf[i]);
return nRead;
}
}
mun.lib.Complex a = new mun.lib.Complex(1,2);
import mun.lib.*; Complex a = new Complex(1,2);
| Class | Derived | Package | Everywhere | |
|---|---|---|---|---|
| public | yes | yes | yes | yes |
| private | yes | |||
| protected | yes | yes | yes | |
| default | yes | yes |
Two levels of control on classes/interfaces:
| Package | Outside Package | |
|---|---|---|
| public | yes | yes |
| default | yes | no |
int[] a; // declares a, no memory allocated int b[]; // same as int [] b; a = new int[10]; // now we have some int's
char[][] screen = new char[24][80];
int[] a = { 1, -2, 3, 10, 2, 0 };
this implicitly calls new int[6] and initializes
the elements of a.
int [][] aa = new int[3][5]; System.out.println(aa.length); System.out.println(aa[0].length);prints 3 and 5.
When applied to:
class Expr {
public static Expr create(String exprStr) {
ExprTokenizer t = new ExprTokenizer(exprStr);
Expr expr = parseOr(t);
if (expr == null)
return null;
if (!t.currentMatches(ExprTokenizer.T_END))
return null;
return expr;
}
// ... rest of Expr
static private class ExprTokenizer {
public static final int T_END = 0;
// ...
public ExprTokenizer(String str) {
// ...
}
public boolean currentMatches(int tok) {
if (type == tok) {
getNext();
return true;
}
return false;
}
// ...
}
}
class Vector {
// ...
// Inner class
class VectorEnum implements Enumeration {
private int pos = 0;
public boolean hasMoreElements() {
return pos < size();
}
public Object nextElement()
throws NoSuchElementException
{
if (pos >= size())
throw new NoSuchElementException();
return elementAt(pos++);
}
}
public Enumeration elements() {
// Creates VectorEnum tied to `this'
return new VectorEnum();
}
// ...
}
class Vector {
// ...
public Enumeration elements() {
// Local inner class
class VectorEnum implements Enumeration {
private int pos = 0;
public boolean hasMoreElements() {
return pos < size();
}
public Object nextElement()
throws NoSuchElementException
{
if (pos >= size())
throw new NoSuchElementException();
return elementAt(pos++);
}
}
// Creates VectorEnum tied to `this'
return new VectorEnum();
}
// ...
}
class Vector {
// ...
public Enumeration elements() {
// anonymous inner class
return new Enumeration() {
// class is expected to implement
// the Enumeration interface
private int pos = 0;
public boolean hasMoreElements() {
return pos < size();
}
public Object nextElement()
throws NoSuchElementException
{
if (pos >= size())
throw new NoSuchElementException();
return elementAt(pos++);
}
}
}
// ...
}
javadoc -private *.java
/* Copyright (c) 1995, 1996 Sun Microsystems,
* Inc. All Rights Reserved.
* ...
*/
package java.util;
/**
* The <code>Stack</code> class represents a
* last-in-first-out (LIFO) stack of objects.
*
* @author Jonathan Payne
* @version 1.16, 01/28/97
* @since JDK1.0
*/
public
class Stack extends Vector {
/**
* Pushes an item onto the top of this stack.
*
* @param item the item to be pushed onto
* this stack.
* @return the <code>item</code> argument.
* @since JDK1.0
*/
public Object push(Object item) {
// ...
}
/**
* Removes the object at the top of this
* stack and returns that object as the value
* of this function.
*
* @return The object at the top of this
* stack.
* @exception EmptyStackException if this
* stack is empty.
* @since JDK1.0
*/
public synchronized Object pop() {
// ...
}
// ...
/**
* Returns where an object is on this stack.
*
* @param o the desired object.
* @return the distance from the top of the
* stack where the object is]
* located; the return value
* <code>-1</code> indicates that
* the object is not on the stack.
* @since JDK1.0
*/
public synchronized int search(Object o) {
// ...
}
}