Java Quick Reference
Language Essentials for Java
NOTE: This is a selected list of key elements of Java, see Sun's Java glossary for a complete description.
applet
A program written in Java to run within a Java-compatible web browser, such Netscape Navigator 2 or higher or Internet Explorer 3 or higher. In HTML used as opening and closing tag to incorporate a Java applet.
HTML code to display applet within a Web page:
<applet code="Clock.class"
width=140
height=130
align=left>
bean
A reusable software component. Beans can be combined to create an application.
class
The fundamental object in the Java object hierarchay, classes inherit methods and variables from superclasses above and pass them on to subclasses below. In Java, the class is a type that defines the implementation of a particular kind of object. A class definition defines instance and class variables and methods. For applets, the file name must match the class name defined within the applet.
public class HelloWorld extends Applet {
statements
}
codebase
Works together with the code attribute in the applet tag to give a complete specification of where to find the main applet class file: code specifies the name of the file, and codebase specifies the URL of the directory containing the file.
codebase= "http://www.myserver.edu/applets/"
comments
Comments in Java are introduced with a double slash (//) at the beginning of the line. Multiple lines are framed by /* and */.
// This is a single comment line.
compiler
A program to translate source code into code to be executed by a computer. The Java compiler translates Java source code into Java bytecode. A JIT or just-in-time complier converts all of the bytecode into native machine code just as a Java program is run. This results in run-time speed improvements over code that is interpreted by a Java Virtual Machine.
extends
Class X extends class Y to add functionality, either by adding fields or methods to class Y, or by overriding methods of class Y
public class NervousText extends java.applet.Applet
method
A behavior or action of a class
if...then
Control structure for creating branching of actions depending on user input or choice. The condition for determining the result must follow if and be enclosed in parentheses. Action to be carried out is defined in curly brackets. Multiple if statements may follow the initial if through the use of else if. If may also be used by itself. Note that the test for equality in Java is a double equal sign (==); does not equal is !=. With functions which return a value of true or false (as in the confirm() function), no equalizing symbol (==) is needed (see confirm() example). Multiple conditions may follow the initial condition (all in the same parentheses) if separated by a double pipe (||) which is equivalent to "or"; to signify "and" (i.e. more than one condition must be fullfilled), use a double ampersand (&&).
if (myvariable == "right input") {
answer1.setText("Right!");
ding.play();
} else {
answer1.setText("Sorry, try again.");
beep.play();
}
indexOf()
Used to search for presence and location of sub-string within a text string. Returns a number corresponding to the number of characters from the beginning of the string. If the searched for sub-string is not found, -1 is returned as a value. LastIndexof() searches backwards for a sub-string.
mystring = "Some text to try out"
test = mystring.indexOf("try")
This returns a value of 13.
param
Parameter tag, used to pass on values from HTML to an applet, allows for customization of applet within HTML without changing the Java source code.
HTML code to display applet within a Web page:
<APPLET CODE="ScriptableClock.class"
NAME="clock2"
WIDTH=300
HEIGHT=45>
<PARAM NAME=bgColor VALUE="White">
<PARAM NAME=fgColor VALUE="Red">
</APPLET>
strings
Text strings are enclosed in double quotes.
newvariable = "This is a text string"
variables
Defined in Java with the = sign.
myvariable = "This is some text"
ITA Resources for Java
Java => Index / Presentation / Code / Guide // AIA Portal
Bob Godwin-Jones