- package
- When a source file gets too large, you can split it up, and
still have it behave much as if it were one file by declaring all
the parts as belonging to the same package. In C++ terminology,
all classes in the same package are friends of each other. You
just add a line such package cmp.business; at the top of
each source *.java file. The more qualification you have
specified in your CLASSPATH the less qualification you are
allowed to specify in your import statements. There is no
redundancy permitted. It is not enough to simply have your class
files on the classpath. They must be in particular locations or
inside jars on the CLASSPATH with just the right embedded path
information. If you can't understand my handwaving, try reading
Sun's
explanation. See import, CLASSPATH, java.exe, package scope.
- package scope
- If you have a variable or method in your class that you don't
want clients of your class directly accessing, don't give it a
public, protected or private declaration. Due to an oversight in the
design of Java, you can't explicitly declare the default "package"
accessibility. Other members of the package will be able to see it,
but classes outside the package that inherit from yours,
won't. The protected accessibility attribute offers slightly
more visibibily. See public, private, protected.
- PackAJar
- Konasoft's tools for preparing JAR files. See JAR.
- PackerLayout
- A custom layout manager more sophisticated that the standard
GridBagLayout manager based on the TCL layout manager. See Layout.
- PAD
- Packet Assembler/Disassembler. One of its jobs is to reassemble
arriving packets in the proper order. It is a small computer owned by the
local packet net company (Datapac in Canada). You can access it using your
modem with a local phone call. The PAD will then route your call via digital
satellite, fibre optic and microwave links almost anywhere on earth. Though
static on the line between your computer and the PAD can cause errors,
once it reaches the PAD, special error detection and correction methods
guarantee your data gets to its final destination with no further errors
added. This method is much cheaper than phoning long distance. Packet nets
use long distance circuits about 250 times more efficiently than 2400 BPS
modems phoning direct. Many modems cannot call directly more than a few
hundred miles because of the static and other distortions. Any modem using
the packet nets can easily reach the four corners of the earth.
- paint
- Actually do the drawing of some component. Does not erase the background
first. The paint routine is not responsible for painting children,
or scheduling their repainting. paints are triggered as the spirit
moves the native GUI. It may call paint at any time. It may even
call your paint routine several times, to paint a single component,
each time with a different clipping region. Container.Paint() calls
each contained flyweight component's paint routine in turn. For efficiency,
it bypasses the call if the component is definitely outside the clipregion.
For heavyweight contained components, the native GUI handles repainting
without AWT involvement. Container.update() behaves similarly. See
also repaint, update.
- panel
- to make Applet layout easier, you break a frame up into regions and compose
each of them separately. Each region is called a panel. Panels don't have
any visible bounding lines. See frame, canvas.
- parallel port
- hardware to which you may attach a parallel printer or Centronics interface
device. See PortIO.
- parameterised types
- See genericity.
- parameters
- parameters are always passed by value not by reference. The called method
gets a copy of each primitive and a copy of the pointer to each object.
The called method can therefore not change any local variables in the caller.
However it can change the contents of objects (which includes strings and
arrays) passed to it. Some people may argue that counts as call by reference,
however a callee cannot make the callers variables point to different objects,
just change the contents of objects. Objects are always accessed
by reference, (literally via a reference) even when parameters are not
involved. You can kludge call by reference by passing values back to your
caller inside an array or by returning a freshly minted object full of
values.
- parent
- parent is not the same thing as a superclass. Roughly speaking parent is
the immediately enclosing graphical element. If a button is in a panel
and the panel is in an Applet we say the panel is the parent of the button
and the Applet is the parent of the panel. A parent can have many children,
but a child can have only one parent. This defines a hierarchy of objects
that describe a screen layout.
- parentheses
- Parentheses, look like this (). Java uses
them for surrounding parameter lists.
See brackets, braces.
- parity
- Modems often use a crude error detecting mechanism by adding an extra bit
to each character sent, so that the number of ones is always even. If static
reverses one of the bits, the result will no longer have an even number
of ones in it and the receiving end will know something has gone wrong.
- parser
- a program that analyses syntax. It might for example look at a piece
of Java source code and find all the variable names, method names and
operators in order to compile it into JVM byte code, or it might analyse
HTML, or your own invented language. The original LEX/YACC/Bison
generated C code. There are now variants that generate Java code. My
personal favourite, based mainly on the accessible documentation is
JavaCC. People who write parsers have a strange language all their own.
The Parsifal glossary
may help. The writers of these tools are academics, and are not
interested in teaching you anything, just impressing you with how
brilliant their programs are. This means the manuals are almost useless.
You have to study examples, and gradually the manuals will begin to make
sense. Authors took six years of university courses to get to their level
of parser understanding, why should they make it any easier for you?
See ANTLR (formerly PCCTS), BYACC, JLEX, JavaCC (formerly Jack),
JavaCUP, Koala, Metamata Parse, PCCTS, SableCC, VisualParse++,
YACC.
- PARTS
- Park Place's class library of pluggable
components for Java. PARTS started life out in Smalltalk.
- Parts For
Java
- This may be the same thing as Park Place's Parts?? A Java IDE environment
similar to Smalltalk.
- PCCTS
- a YACC-like parser-generator, now renamed to ANTLR. Scott Stanchfield
has written a tutorial. See ANTLR,
parser, YACC.
- PCGrasp
- A code beautifier. See beautifier.
- peer
- Associated with each component are three objects -- e.g. the
standard AWT button object, a peer mirroring interfacing button
object constructed in the style that the native GUI likes, and
perhaps also a hidden button object internal to the native GUI.
The behavior of the particular component can depend heavily on
the peer. The peer object for a button, for example, contains
platform-dependent code to hook into the native GUI Windows 95
button-drawing code, whereas the AWT button object would be
identical for all platforms. The same Java program may behave
quite differently on different platforms, following the maxim,
when in Rome do as the Romans.
-
PERC
- A clean-room, modified JVM to handle Real Time and embedded Java
systems. It supports accurate real-time garbage collection and
deterministic real-time tasking.
-
Percolator
- A Java source code beautifier. It does a quite number of things
besides just re-indenting It will break long lines, sort methods and
variable definitions and add comments. See beautifier, coding standards.
- persistence
- Writing Java objects to disk in a way that they can be read back in again
later. See serialisation.
Personal Bookshelf
- A free service of MacMillan Publishers to let you browse 200
computer books online. They have titles from Adodbe, Cisco,
Queue, Sams and Ziff-Davis. They also have Betabooks -- previews
of books not yet published. There are some Java books in the
suite. The catch is you have to fill in form after form giving
all manner of data about yourself including answers to personal
questions that are none of their damn business. What is even more
infuriating is the questions are not optional. The other catch is
the server is heavily overloaded resulting in slow response,
timeouts and various server errors.
It Library has a similar read before
you buy policy.
Another book you can read online, is Bruce Eckel's Thinking
in java (ISBN: 0-13-659723-8) also available for
purchase as a 1152 page book from Amazon.
Another book you can read online, is Doug Lea's Concurrent
Programming in Java: Design Principles and Patterns
(ISBN 0-201-69581-2) also available for purchase as a 339 page
book from
Amazon.
Core
Web Programming (ISBN: 0-13-625666-X) by Marty Hall
and Gary Cornell is pretty well the only book on using CGI and
client-side Java together. Marty has posted all the
source code examples from the book for anyone to use. These
contain updates and errata fixes you don't get on the CD-ROM that
comes with the book.
- Personal Java
- The full Business Java language with the enterprise communications stripped
out of it (no remote RMI). It also has no security breakout. It still contains
the AWT GUI. This is the Java you might see in a pocket organiser. See
Business Java, Embedded Java, Windows CE.
- PGP
- Pretty Good Privacy. A technique for
encrypting and digital signatures based on the difficulty of
finding the prime factors of very large numbers.
PGP is different from other digital signing/encryption techniques
in that there are no central certificate issuing authorities. You
make you own certificates (containing just your name, email
address and public key but not your private one), and get other
ordinary people to digitally sign them as accurate. This creates
a web of trust. You know if a certificate is valid by how much
you trust the people who signed the certificate. You tell PGP how
much you trust various certificates and how much you trust
various people to accurately sign other's certificates and it
computes a trustworthiness of each certificate on your keyring.
There is a central repository of certificates where you can add
your public key at
http://www.nai.com/products/security/public_keys/add_key.asp.
However, Network Associates Products (the makers of PGP) make no
claims that any of the certificates there are valid.
The PGP people don't use the term certificate like
everyone else does. They call them public keys even though
the public key files contain more information than just the
public key. They use an single key icon to represent a public
key, and a double key icon to represent a public/private pair. Be
careful you don't accidentally give you private key to anyone by
accidentally exporting both keys.
You learn of other's public keys by picking them off websites.
For example, you can download/see my PGP public key at http://mindprod.com/RoedyGreenPGPkey.asc.
It just looks like gibberish, but when you import it into your
PGP keyring it contains my public key, name and email address
hidden in there. Once you declare my public key as trustworthy,
then you can send me encrypted email, and you can verify if any
digitally signed mail from me really came from me. It won't let
me send you encrypted email. (I need your public key for
that.) It won't let me verify that email from you really came
from you. (I need your public key for that.) Of course you
need the PGP software installed on your machine. You can download
it free.
PGP is easiest to use if you have a mailer like Eudora Pro 4.1
that integrates it. The integration is somewhat inept. Signed
messages arrive as mysterious enclosures looking like junk all
called smime.p7. If somebody sends you a message signed in the
message body, Eudora fails to notice or even let your verify the
signature. You can still digitally sign and/or encrypt your
messages with PGP by having it sign the clipboard then paste the
text back into pretty well any newsreader/mailreader. That way
your mailreader/newsreader need not support PGP directly.
Unfortunately only the message body then is signed. The header
including the message subject:, to: and from: are unprotected.
The add-on PGPeep partly integrates PGP into Forte Agent, however
it is not smart enough to include the signature line in the
digitally signed part of the message. This area of integration is
still in its infancy. It is not ready for the masses. It must
become totally transparent.
You can receive PGP certificates via unsecured email. You can
discover them in Newsgroup postings. You can look them up at the
PGP central database at
http://www.nai.com/products/security/public_keys/lookup_key.asp.
PGP uses the SHA-1 digest type for signing email. See
certificate, digital signing, security. SHA-1.
- philosophy
- If you want to understand the philosophy behind Java, see
Bruce Eckel's Thinking
in java (ISBN: 0-13-659723-8) also available for
purchase as a 1152 page book from Amazon
for $32 US. See design patterns, algorithms, data
structures, UML.
- pickle file
- The file that contains the persistent state information for a JavaBean
object. See JavaBeans
- PicoJava
- The smallest of the Sun Java silicon chips. You can find a wealth of material
on them by using the Sun search engine. See
JVM..
- picon
- a Personal Icon that may be a photo or a logo displayed while people are
reading your posts or email. The Galahad Internet browser supports picons.
The University of Indiana provides a registry for both personal and institutional
picons. You can also assign your own picons to other people to classify
in whatever way you want. These sound like a frill, but are a serious tool
to help in dealing with information overload.
- Pizza
- a superset of Java that adds templates, closures and algebraic data types.
- PLAF
- Pluggable Look And Feel. Swing's ability
to change the look and feel of a Applet or application on the fly.
Plafable components automatically change to track the current look and
feel.
- Plan
9
- AT&T's new distributed operating system. See Inferno.
- Platibus
- a version control system.
- play
- play pre-recorded audio on a sound card. Java does not yet have a standard
set of beeps and clicks.
- plumbing
- The technical term for the code that manages data structures,
persistence, inter-computer communications, database access etc.
-- all the technical details that are very necessary for an
application to work, but are not application specific.
By analogy, just as plumbing and electrical wiring is normally
hidden from view behind the walls of a house, so ideally should
such plumbing be hidden away in library classes so it does not
clutter up application-specific code. See bubblegum.
- PNG
- *.png (Portable Network Graphic) files
are a replacement for *.gif files when you don't need animation.
JPEG files have better compression for photographs but don't
handle line art as well as gif and png formats. PNG have been one
of the standard image formats in Netscape and Internet Explorer
since 1997. Opera started native support with version 3.51. Unlike GIF
files, there are no patent restrictions, and the file format is
maintained in an open source environment. You can get on a mailing list
if you want to be kept informed of the latest developments.
feature |
GIF |
JPG |
PNG |
colour resolution |
8 bits |
24 bits |
8, 24, or 48 bits |
grey resolution |
8 bits |
8 bits |
8 or 16 bits |
transparency |
1 level |
none |
256 levels |
lossy compression |
no |
yes |
no |
lossless compression |
yes |
unused |
yes |
patent restrictions |
yes |
no |
no |
animation |
yes |
no |
no (see MNG) |
PNG compression uses zlib, same as the gnu gzip and Java jar utilities.
On most 8-bit images, the PNG form will be about 11% smaller than the GIF
form. Sun will be supporting PNG officially in Advanced Imaging Kit.
If you use the Opera browser, you can download 3.51 which has
native PNG support. You can also retrofit it into older version
with the PNG
Live Plug-in. Make sure you download
version 1 since version 2 works only with Netscape. After you
have installed you should see this in Opera's Plugin Window:
PNG Live 1.0 (Beta)
*image/x-png
png
C:\Program Files\Opera\plugins\NPPNG32.dll
You can test your browser's PNG support here.
See GIF, JPEG, MNG, WIF, Opera.
- Pnuts
- A platform independent Java-like scripting language implemented in Java.
- pointer
- Java does not have pointers like C or C++. It has something
almost as powerful, but many times safer called
"references". (Java refers to them as pointers in one
place, the NullPointerException). They are like pointers, except
that the dangerous features are removed, namely, pointer
arithmetic, random initialisation, dangling pointers to deleted
objects, mismatched types and unions. You can't construct
references out of thin air. Unlike pointers, references cannot
point into the middle of an object. References are null or always
point to something valid of the type they claim to. See
References.
PolarDoc
- a replacement for Sun's JavaDOC. PolarDoc also documents inner classes.
- polymorphism
- The generic term for having many forms. You can use the same name for several
different things and the compiler automatically figures out which version
you wanted. There are several forms of polymorphism supported in Java,
shadowing, overriding, and overloading.
- POP3
- Post Office Protocol version 3. The
protocol most commonly used for fetching mail from a server. Some
POP3 servers can also be used to send mail. The advantage of POP3 or
sending is it will work even if you come in to pick up your mail via a
foreign ISP. Further it has better authentication. See SMTP, IMAP, GoodHost,
Hacksaw, MassMail, JavaMail.
- port
- A port can be a serial port for a modem to connect to, or a
parallel port for a printer to connect to. It simply deals with
the handshaking of sending a single character at a time to an
external device. The Internet's DNS/IP protocols only deal with
delivering a packet to the right computer. Once arrived the
packets must be assembled in order into messages and delivered to
the right application. Applications are assigned numbers from 0
to 65535 called ports. Any message destined for port 80, for
example, is delivered to the application handling HTTP requests.
The port number can be explicitly embedded in a URL like this
"www.mindprod.com:80". Some of the port numbers are up
for grabs on any machine for your own code. Others have standard
assignments. IANA maintains the list
of "well known" port numbers.
Port name |
Port number |
echo, used for testing. |
7 |
DayTime,
returns date/time as a string. |
13 |
FTP, File Transfer Protocol |
20 and 21 |
SMTP, Simple Mail Transfer Protocol |
25 |
Time, returns 32-bit days since 1900/01/01. |
37 |
HTTP, HyperText Transfer
Protocol |
80 |
DNS, Domain Name Service |
53 |
POP3, Post Office Protocol version
3 |
110 |
NTP, Network Time Protocol,
64 bit number with 32 bits as the integer and 32 bits as
the fractional portion of seconds
since 1900/01/01. |
123 |
utime |
519 |
timed timeserver |
525 |
SNTP, Simple Network Time
Protocol heartbeat. |
580 |
dbAnywhere |
8889 |
- portability
- The main point of Java is that your code should run on any platform without
changes, without even recompiling. Portability is a Good Thing TM even
if you don't plan to run the program on more that one platform. Why? Portability
leaves open the option to upgrade hardware, or to jump ship to some other
operating system if your current vendor misbehaves. It makes it easier
to upgrade to future versions of the current operating system. It leaves
open the option to reuse or sell your software to some other user with
different hardware or operating system. It makes it easier to get help.
No matter what platform your expert uses, he can still run or debug your
code for you. Unfortunately, manufacturers of hardware and operating systems
historically have done their darndest to discourage portability. It is
to their economic advantage to lock you in to their hardware or OS. We
programmers and users need to fight back by avoiding Java tools that lock
you in to one platform. Ease of switching platforms encourages vigorous
competition between vendors. Peter Linden recommended having a look at
this essay
on the issue. The flip side of this issue is that Sun has made some major
boo-boos which then are forced on the entire industry. These include a
Date/Calender set of classes only their mother could love, lack of consistency
in the naming of conversion functions and i/o methods, and a serialisation
technique that is slow and incapable of handling even a 1000-element list.
PortIO
- Java does not officially support serial or parallel ports, however Central
Data has created the PortIO interface and an implementation for their EtherLite
® serial/parallel cards. It works with a streams interface. The source
code is in the public domain to make it possible to port to other port
hardware or platforms. See serial port, parallel port.
- post
- Posting an event refers to the JDK 1.0 process of giving an
event to a parent if the child did not completely handle it or
vice versa. The postEvent routine for a component typically
immediately calls the component's handleEvent method. If
handleEvent returns false, indicating the event is not yet
completely handled, postEvent then calls the parent postEvent,
percolating it on up. (The percolating may be done by the
parent's postEvent, or if it doesn't handle it by the component's
postEvent.) If nobody handles it, postEvent posts the event to
component's peer. The key fact to understand is that postEvent
insists on immediately completely handling the event. It does not
requeue it to be done later. In JDK 1.1 "post" refers
to putting an event into a queue destined for components. See
also dispatch, deliver, handle. In datacommunications, post
meants to place at electronic message in a public Internet
usegroup newsgroup for all to see.
- PostScript
- A full-blown computer language used by typesetters, printers
and screens to draw graphics and text in a resolution-independent
way. Java programs will use the Bravo interface to generate
PostScript programs that are then interpreted for printer, screen
or typesetter. See Aandi
Inston's PostScript
Resource Page and his remarkable (but expensive $420 CDN)
tool for composing and debugging PostScript PSAlter.
You need quite at least three textbooks to have much hope of
understanding PostScript. I suggest starting with the
official books from Adobe:
Postscript Language Tutorial and Cookbook (ISBN:
0-201-10179-3), $20 US, also known as the Blue Book. If you buy only one book, get this one.
Postscript
Language Reference Manual (ISBN: 0-201-18127-4), $30
US, also known as the Red Book, even though it is now white. The
third
edition (ISBN: 0-201-37922-8), $40 US, should be out soon.
Postscript Language Progam Design (ISBN:
0-201-14396-8), $22 US, also known as the Green Book.. This
explains how PostScript works under the hood. PostScript made
little sense to me until I read this book. Then again I come from
a Forth background, and like to think very concretely about what
is going on.
Adobe Type 1 Font Format (ISBN: 0-201-57044-0), $17
US, also known as the White Book (not to be confused with the Red
Book which now has a largely white cover). This explains how
PostScript fonts work under the hood, including the formerly
secret proprietary encryption technique. You can probably live
without this book, but I found it satisfied a deep set of
curiosity itches.
See Bravo,
GhostScript.
-
Power
- To raise a number to a power, you can use Math.pow(double
x, double p). For squared and cubed you can use x*x
or x*x*x. For other integral powers you can use Patricia
Shanahan's method:
/**
* Raise a double to a positive integer power.
* Fast version of Math.pow.
* @param x number to be taken to a power.
* @param n power to take x to. 0 <= n <= Integer.MAX_VALUE
* Negative numbers will be treated as unsigned positives.
* @return x^n
*/
public static double power(double x, int n)
{
int bitMask = n;
double evenPower = x;
double result;
if ( bitMask & 1 )
else
bitMask >>>= 1;
while ( bitMask != 0 )
{
evenPower *= evenPower;
if ( (bitMask & 1) == 1 )
bitMask >>>= 1;
} // end while
return result;
} // end power
-
PowerJ
- Sybase's rapid application development (RAD) Java development
tool formerly code-named "Starbuck" then
"Jato" based on Optima++.
- PPP
- Point To Point Protocol. The
protocol for dialling up an Internet provider. It lets you
simultaneously browse remote machines while file transfers go on
in the background. It is gradually replacing the older, slower
and more complicated to configure SLIP protocol. PPP also lets
you send Novell Netware traffic over the line to simulate a
LAN.
- PPTP
- Microsoft's Point To Point
Tunnelling Protocol. The protocol for dialling up
an Internet provider then out over the Internet then into a
Microsoft LAN. It lets you do the same sorts of things you could
over a local LAN.
- precedence
- Java inherits a very complicated operator precedence scheme
from C. Operators with lower precedence numbers are done first.
The advantage of precedence is it means you need fewer
parentheses. The disadvantage is you must memorise this table
perfectly to understand what code will do. Once you learn this
table you will know if:
x = a | b & c;
means:
x = (a | b) & c;
or
x = a | (b & c);
Precedence |
Operator |
Association |
1 |
++ --
(unary) + - ~ !
(cast) |
Right |
2 |
* / % |
Left |
3 |
+ - |
Left |
4 |
<< >> >>> |
Left |
5 |
< > <= >= |
Left |
6 |
== != |
Left |
7 |
& |
Left |
8 |
^ |
Left |
9 |
| |
Left |
10 |
&& |
Left |
11 |
|| |
Left |
12 |
? : |
Right |
13 |
= *= /= += -=
<<= >>= >>>=
&= ^= |= |
Right |
- PreparedStatement
- See Statement.
- pretty-printer
- a program that reformats Java source to standard indentations
and prints it. It may also use colour, bold, italics or type
faces to highlight syntactic elements. A beautifier, in contrast,
outputs tidied Java source, which cannot currently contain any
rich text elements. Marc
W.F. Meurrens maintains a list
of code beautifiers and pretty-printers. See beautifier, cbVan,
JavaToHtml.
- Primes
- A number divisible only by itself and one. Primes are useful
in constructing Hashtables. You can download Java source code to
perform an Eratosthenes sieve to compute the primes, whether a
number is prime, or the next prime above or below a given number.
See hashTables.
- primitive
- Primitive variables include boolean, char, byte, short, int, long, float
and double. Strings, arrays and objects are not primitives.
Type |
Signed? |
Bits |
Bytes |
Lowest |
Highest |
boolean |
n/a |
1 |
1 |
false |
true |
char |
unsigned Unicode |
16 |
2 |
'\u0000' |
'\uffff' |
byte |
signed |
8 |
1 |
-128 |
+127 |
short |
signed |
16 |
2 |
-32,768 |
+32,767 |
int |
signed |
32 |
4 |
-2,147,483,648 |
+2,147,483,647 |
long |
signed |
64 |
8 |
-9,223,372,036,854,775,808 |
+9,223,372,036,854,775,807 |
float |
signed exponent and mantissa |
32 |
4 |
±1.40129846432481707e-45 |
±3.40282346638528860e+38 |
double |
signed exponent and mantissa |
64 |
8 |
±4.94065645841246544e-324 |
±1.79769313486231570e+308 |
See literal, binary formats, IEEE 754, unsigned.
- Principle Of Least Astonishment
- In designing a language or computer program, generally, you should ensure
the effect of any command is the one that least astonishes the user. See
gotchas.
- printf
- See the java.text.DecimalFormat and java.text.NumberFormat
classes in JDK 1.1. Unfortunately, Java 1.0.2 has no equivalent
to the C printf or sprintf function for formatting numbers for
display. You have to roll your own. One such class is available
from San Diego State University called sdsu.FormatString.
Acme
also has one. Eliote Rusty
Harold did one. Gary Cornell and Cay Horstmann's book Core
Java includes one. The Lava
Rocks tutorials also includes one. See format, println
format, NumberFormat.
- printing
- There are two kinds of printing:
- When you know the brand of printer you have and the control codes
it likes, and you want to send raw bytes to it. Most often you want
to do this when your printer handles PostScript.
- You don't know what kind of printer you have. You want to use
generic methods and have the operating system convert them into
the codes the printer likes. For this technique to work, the
printer must be configured in the OS with a device driver, and be
accessible to your program as the default printer.
For the rest of this discussion, we are referring only to the
second type printing. For the first, see parallel port, and
System.exec.
The Java 1.0 JDK does not support printing. JDK 1.1 does, via
java.awt.PrintJob. You print using the same techniques you use
for drawing on the screen. It is much like drawing a high-res
screen the size of a sheet of paper. Components now have a print
method to print themselves which is usually the same as the one
to draw them on the screen. To handle text you use Canvases and
drawString, or TextFields. To get properly aligned text without
borders, consider the KL-Group components or Swing. Applets
cannot print, with one exception, signed applets running under
IE4 in JDK 1.1. For example to print everything in a frame:
PrintJob pj = getToolkit().getPrintJob(theFrame, jobTitle, null /* properties */ );
// get Printjob object.
Graphics pg = pj.getGraphics();
// get Graphics object for the first page.
printAll(pg);
// print this component and its subcomponents, at (0,0).
pg.dispose();
// release the first page to the print queue.
pg = pj.getGraphics();
// get graphics object for second page.
pg.drawLine(0,0,100,100);
// draw directly onto the graphics object as if it were a canvas.
pg.dispose();
// release the second page to the print queue.
pj.end();
// Finish off the print job, start printing.
In Win95 and NT, the print job properties are ignored. They are system
dependent. But here is how Sun implements them:
howPrint.put( "awt.print.destination" , "printer" );
// could be "printer" or "file", default "printer"
howPrint.put( "awt.print.fileName" , "TEMP/TEMP.PRN" );
// file to receive the PostScript or other physical printer commands
howPrint.put( "awt.print.numCopies" , "1" );
// default 1
howPrint.put( "awt.print.orientation" , "portrait" );
// could be "portrait" or "landscape", default "portrait"
howPrint.put( "awt.print.paperSize" , "letter" );
// could be "letter","legal","executive" or "a4". default "letter"
howPrint.put( "awt.print.printer" , "lp" )
// name of command/utility that will do the printing
howPrint.put( "awt.print.options" , "" );
// options to pass to the print command/utility
PrintJob pj = getToolkit().getPrintJob(theFrame, "Print Test #1" , howPrint);
Graphics pg = pj.getGraphics();
printAll(pg);
pg.dispose();
pj.end();
Here is a little PostScript grid.ps program.
copy grid.ps lpt1: (where lpt1: is a PotstScript printer) to
print out a 1/10" by 1/6" grid on transparent film. It
will be useful in designing or checking printouts, especially those
on pre-printed forms. See Bravo, JDK.
- println format
- PrintStream.println and PrintStream.print display binary data
as a stream of human- readable characters. The formatting is
primitive. To see how it works have a look at this essay. See binary format.
- private
- If you have a variable or method that you want no one else to
use, declare it private. Even programmers that extend your class
won't be able to use it. See public, protected, package.
- procedure
- "procedure" in Pascal is a "static void
method" in Javanese. See method.
- projection
- In SQL, a high fallutin' word for listing the columns you
want included in the results of a query, i.e. the list of fields
in a SELECT statement. In dbAnywhere, a Projection object is an
non-visible object your program can interact to get or set the
value of some particular column in an SQL table. For example, if
you wanted a dummy object that did not display on the screen, but
that gave you program access to the database values in a column,
you would use a Projection object that implements the ProjBinder
interface. I think you would still need a ProjBinder object to
glue it to the RelationView object. dbAnywhere, ProjBinder
- Projects
- I have written an essay describing quite a few student
programming projects. Some are quite simple, some very advanced.
You are welcome to the ideas.
- ProjLink
- In dbAnywhere, a ProjLink is an interface to bind GUI objects
to a particular column of the database. A ProjLink interface
provides methods for the GUI object to report data changes to the
database (notifySetData), and for the database to report changes
to the GUI object (notifyDataChange). For example if you had a
dbAware GUI textfield, it would implement the ProjLink interface.
There would be a ProjBinder object to glue it to RelationView
object. The GUI object needs a setBinding method that creates the
link by calling RelationView.bindProj. setBinding is not part of
the ProjLink interface. See ListLink, Link, Binder,
dbAnywhere
- properties
- A platform-independent generalisation of the DOS SET
environment, or the Windows *.INI files. In Java, even each
object could have its own list of properties. A program can
determine if an entry is missing in the property file and provide
a default to using it its place. There is no hierarchical
structure like the NT registry, not even sections as with the Win
3.1 INI files. Properties also can be used to store other sorts
of key=value data on disk. You can interrogate the run-time
environment with code like this:
// get a system property
String vendor = System.getProperty( "java.vendor" );
System.out.println(vendor);
To discover the entire list of supported system properties and their
current values you could use code like this:
import java.util.Properties;
import java.util.Enumeration;
// Get a list of all the system properties and their values
// Not available in Applets, only applications.
Properties sysprops = System.getProperties();
for ( Enumeration e = sysprops.propertyNames(); e.hasMoreElements(); )
{
String key = (String) e.nextElement();
String value = sysprops.getProperty(key);
System.out.println(key + "=" + value);
} // end for
The System properties are generated by a magic native method
System.initProperties. There is no corresponding jar element or
*.properties file on disk.
file.
In contrast, ordinary Properties are usually loaded into RAM in
their entirety and indexed for rapid Hashtable access and are
later saved to flat files on disk with the *.properties extension. Properties
files on disk are similar to the old Windows 3.1 INI files,
except they have no [..] sections. They are ASCII text files of
keyword=value pairs. Comments begin with #. Lines may be
continued by ending them in a trailing \. Lines are terminated by
a linefeed, not necessarily a CrLf as is common in Win95. Look at
any *.properties files such
as font.properties file to
see an example.
It will look something like this:
# @(#)font.properties 1.10 98/10/09
#
# AWT Font default Properties for Windows
#
dialog.0=Arial,ANSI_CHARSET
dialog.1=WingDings,SYMBOL_CHARSET,NEED_CONVERTED
dialog.2=Symbol,SYMBOL_CHARSET,NEED_CONVERTED
The key thing to understand is that, in RAM, Properties are just
Hashtables. However they can be backed up to flat files that look like
*.INI files. These files are loaded as a whole into RAM Hashtables for
searching. The files are never linearly searched to look up keys.
Searching is always done with the RAM-resident Hashtable. You could
access a property in fonts.properties like this:
// get an ordinary property
import java.io.*;
import java.util.Properties;
...
Properties fonts = new Properties();
try
{
FileInputStream fis = new FileInputStream( "D:/vcp/java/lib/font.properties" );
fonts.load(fis);
fis.close();
}
catch ( IOException e )
String desc = fonts.getProperty( "dialog.1" );
System.out.println(desc);
System
PropertyName |
Description |
accessible
in Applet? |
file.separator |
File separator (e.g., "/") |
yes |
java.class.path |
Java classpath |
no |
java.class.version |
Java class version number |
yes |
java.home |
Java installation directory |
no |
java.vendor |
Java vendor-specific string |
yes |
java.vendor.url |
Java vendor URL |
yes |
java.version |
Java version number |
yes |
line.separator |
Line separator |
yes |
os.arch |
Operating system architecture |
yes |
os.name |
Operating system name |
yes |
path.separator |
Path separator (e.g., ":") |
yes |
user.dir |
User's current working directory |
no |
user.home |
User home directory |
no |
user.name |
User account name |
no |
Properties files have the form key=value where the key may not
contain spaces. You can use _ (underscore) in key names to
represent a space. Since Propreties are Hashtables, they scramble
the order of the elements. If you want to preserve order, and
don't need key lookup, you can parse the file yourself with a
StreamTokenizer and put it in an array. See the code for Learn To Count which
retrieves its ordered list of languages and classes from a
properties file.
Property has a second meaning. In JavaBeans, components have associated
persistent objects. You can modify various fields in those objects to configure
them. The accessible fields of a JavaBean are called "properties".
They are accessible via public get/set methods. There need not be an actual
field, just the get/set methods that simulate one. These are a completely separate mechanism.
See JavaBeans.
- proprietary
- A pejorative term for an innovative concept that is not quite ready for
prime time.
- protected
- If you have a variable or method in your class that you don't want clients
of your class directly accessing, declare it protected. Classes who extend
your class will still be able to use it even if they are not part of the
same package. The Default package accessibility has slightly more
restricted visibility. Consider the following code:
public class A { protected int p };
// presume class B is in a different package from A
class B extends A {
void myMethod()
{
p = 1; // ok
A a = new A();
a.p = 1; // not ok, p would have to be public for this to work.
}
}
See public, private, package.
- protocol
- Since the phone lines have static, and since phone calls mysteriously disconnect
from time to time, and since, in general, modems have no facilities to
handle these problems, we need ways to detect and correct errors in software.
There are all sorts of schemes of doing this. When two computers get together
by modem, you have to decide on which of these methods (protocols) to use.
Unfortunately there is no automatic way of handling this. In descending
order of my personal preference, here are some of the protocols:
TCP/IP, ZOOMIT, ZMODEM, KERMIT, TELINK, YMODEM, XMODEM, ASCII.
The
term can be more general, describing the rigid rules by which any two
programs communicate.
- prototype
- A design pattern useful when the classes to instantiate are
specified at run time, e.g. dynamically loaded. The prototype
object factory uses exemplar (prototype/example) objects that it
simply clones to produce the desired objects. The factory need
know nothing of the class structure of the objects it creates.
See design pattern.
- proxy
- A server that stands between your machine and the potentially
hostile world of the Internet. Instead of directly asking
machines on the Internet to do things for you, you ask the proxy
server to ask your behalf. In return for this loss of directness
and freedom, the proxy web and ftp servers may cache your pages
and data resulting in faster access. If the proxy implements a
firewall it also attempts to protect you from the hostile world,
and your own stupidity. A proxy makes a group of users behind the
firewall look like a single very active user to the outside
world. It makes all its requests of the Internet via a single IP.
When results come back, it remembers who internally was talking
to that external site. Proxy is also one of the design patterns.
See design patterns. see design patterns, firewall.
- pseudocode
- When someone wants to give you just the outline of an
algorithm, he may write it out in an ad hoc language that is a
cross between English and various computer languages he may know.
No computer can compile it. It leaves out too many details.
- public
- If you have a variable or method you want users of your class
to be able to access, you must declare it public. See private,
protected, package.
- Pure Java
- Java written without any custom native classes certified
portable by Sun.
- Pure Java Developer's
Journal
- Cobb Group, Ziff-Davis's Java magazine. See Java Developer's
Journal.
- pure virtual
- In C++ a pure virtual function is one defined as having a
dummy implementation, the infamously goofball "=0"
syntax. This means you can't instantiate any objects of this
class because that method is deliberately undefined. You must
override it in some subclass with a real definition. The Javanese
way of doing this is to declare a method "abstract".
See abstract, virtual.
- push server
- A server than selects information for you and preloads it
onto your local machine, and keeps it up to date so that you can
begin reading immediately. PointCast is a well known push
service. HotBot from hotwire
takes another approach. In contrast, with a pull service, the
local machine does the selecting logic.
- PVCS
- Intersolve's pioneering work on a Poly Version Control
System. This allows you to track changes to software, to maintain
multiple versions, and to undo changes that did not work out. In
future, version control systems will work at much finer
granularity, allowing programmers to work much more independently
without interfering with each other and will make it much easier
to mesh the work of different programmers. A job concept similar
to the map maker or circuit designer's layer is the key. In
future, version control systems will store the deep structure of
a program (in Chomsky's sense), rather than some particular
textual representation. In other words, they will store source
code as a directed graph (nodes and references) in a database and
manipulate it as such rather that treating it as text and
manipulating it with a text editor as we do now. This will allow
you to view the same program is many different representations
(e.g. decision table, flow chart, or traditional Java) without
disturbing the data stored in the version control database. See
jaunt, TLIB.
- PVM
- PVM (Parallel Virtual Machine) is a software package that
permits a heterogeneous collection of Unix computers hooked
together by a network to be used as a single large parallel
computer. Thus large computational problems can be solved more
cost effectively by using the aggregate power and memory of many
computers. The software is very portable. The source, which is
available free through nettle, has been compiled on everything
from laptops to Crays. See JavaPVM and JPVM.