Java White Paper Description: Simple Object-Oriented Distributed Interpreted Robust Secure
Java White Paper Description: Simple Object-Oriented Distributed Interpreted Robust Secure
simple
Java for Network Programming object-oriented
secure
1 2
3 4
Dierences from C++ Dierences from C++, cont'd
not just a language, but an entire execu- no preprocessor
tion environment
no macros, no #dene'd constants, no #include
has: methods are not explicitly declared virtual
separate interface and implementation inheritance, public and non-nal methods are virtual
threads, exception handling
does not have: abstract instead of = 0 for pure virtual
methods
separate class declaration, pointers,
globals, structures, unions, enumerated types,
typedefs, templates, operator overloading
limited access to underlying system (through
single implementation inheritance System Properties)
no getenv()
multiple interface inheritence
5 6
package lang
* @version 0.1
*/
public class Foo extends Bar implements Baz
{
/** { Object, Class, Thread, Math
* constructor: accesses private instance member
java.io package
API, cont'd
System.out.println (\hello");
package util
le output
BitSet, Date, Hashtable, Vector, Stack, etc.
{ FileOutputStream
package applet { PrintStream
{ extend class Applet
{ security restrictions: limited access to environ- le input
ment
{ FileInputStream
{ init() entry point instead of main()
{ DataInputStream
Thread scheduling
scheduling is implementation dependent Thread groups
{ cooperative on Solaris 2.x
{ time-sliced on Windows a Thread is always constructed in a Thread-
Group
priorities
can specify other than the (default) main
{ MIN PRIORITY == 1 Thread
{ NORM PRIORITY == 5
can perform operations on all Threads in
{ MAX PRIORITY == 10 a ThreadGroup
daemonize, suspend, resume, stop
ThreadLister utility
15 16
Example: Moderator Thread
import java.util.Enumeration;
import java.util.Hashtable;
import java.io.*;
17 18
Example: Debater
Example: Moderator, cont'd import java.io.*;
19 20
Exceptions and Errors
Exceptions and Errors, cont'd
Exceptions must be caught or thrown
example of user-dened Exception:
Errors and RuntimeExceptions need not
be handled: they get passed up the call public class InvalidDebaterException extends Exception
{
stack /**
* Constructor.
*
* @param debater the name of the invalid debater
*/
all have getMessage() method for retriev- public InvalidDebaterException (String debater)
{
ing message String }
super (debater);
21 22
Idioms
java.net package can have main() for each class, for testing
provides passive ServerSocket and active toString() method permits implicit con-
Socket classes version
25 26
CLASSPATH
environment variable or command line ar-
Packages
gument
name with package statement
contains any number of directories
colon separated on UNIX, semicolon on Windows naming convention: EDU.wustl.cs.544.< ::: >
directories searched for root of a package access other packages with import state-
hierarchy ment
if package EDU.wustl.cs.544.user.utils is rooted import EDU.wustl.cs.544.user.utils.*;
at /home/user/classes/cs544/java, then
CLASSPATH should contain
.:/home/user/classes/cs544/java
27 28
Javadoc
for documenting public classes, methods,
and data members
Javadoc special tags
{ package listing
@version (does not seem to work?)
{ package tree
{ name index
@author (does not seem to work?)
{ detailed descriptions
@see classname
javadoc [-d directory] package/le names
@param name description
start javadoc comment: /**
@exception name description
end javadoc comment: */
@return description
can contain most HTML tags and special
tags
29 30
Limitations
Thread interruption not supported by cur- Resources
rent implementations
http://java.sun.com
{ language reference
ThreadDeath doesn't appear to always be
caught { virtual machine reference
31 32