SCOUG Java Programming Class 1
Outline
Object Oriented Programming Concepts
Syntax -
Very similar to C and C++
Statement delimiter is ; Blank lines anywhere, continuation character (if needed) is \
Comments can be added by using:
Block structure used to begin and end related statements using { }. Variable scope, by default, is limited to the block (and any nested blocks) in which it is defined.
Names (field, method, class) must begin with a letter, underscore or dollar sign; remaining characters can include digit (0-9). Java implicitly supports unicode so "letter" means lower or upper case a-z plus unicode values greater than x00c0. There are approximately 50 reserved names which cannot be used.
Modifiers for fields, methods and classes determine accessibility from external and sub classes:
Modifier |
Meaning |
public |
available to all classes |
protected |
available to this class and its subclasses only |
private |
available to this class only |
(none) |
available to containing package |
static |
combinative to specific one instance of variable or method across all objects of class |
final |
cannot be subclassed |
abstract |
incomplete (cf interface) |
Special names include:
Intrinsic Data Types -
Operators -
Statements -
Class Model -
Classes are strictly hierarchical - multiple inheritance not provided. Classes are defined using the "class" keyword with appropriate modifiers as described above. The class definition will contain its instance variables and objects as well as its methods. A special method called the constructor is identified by using the class name as its name.
The class methods (including the constructor) can be "overloaded" meaning that the same method can be defined serveral times. Each definition must contain a unique set of input parameters.
Classes can be:
Interfaces are collections of abstract classes that are used to indicate content. They are defined using the "interface" keyword and may contain only static fields and/or a list of methods (which are automatically abstract). The listed methods must be defined by any class which implements the interface (this is their main purpose).
Packages are groups of related classes and/or interfaces. The benefits of combining classes into a package are:
To create a package, you must include the "package" statement at the beginning of each class file in the package. This statement contains the package name. Example: package Polygons
Component |
Description |
Command Line Options |
javac |
Compiler |
g,O, debug, depend, nowarn, verbose, classpath path, nowrite, d dir |
java javapm applet |
Command window interpreter PM window interpreter Applet viewer |
cs, classpath path, ms x, noasyncgc, prof, ss x, oss x, verbose, verify, verifyremote, noverify, verbosegc |
javap |
Uninterpreter |
p, c, classpath path |
javadoc |
Documenter |
|
javah |
Create C-header file |
o outputfile, d directory, td directory, verbose, classpath path |
jdb |
Debugger |
Source input is maintaned in .java files; compiled output is to .class files. There can be only one public class defined in each .java file; its name must match the name of the file.
Java and JDK as referenced herein are protected by the following copyright notices:
© Copyright Sun Microsystems Inc, 1992-1997. All rights reserved.
© Copyright IBM Corporation, 1996-1997. All rights reserved.
The JDK is based in part on the work of the Independent JPEG group.
The Java technology is owned and exclusively licensed by Sun Microsystems Inc. Java is a trademark of Sun Microsystems Inc. in the US and other countries.