Java Reference
In-Depth Information
AppendixB
j--Language
B.1 Introduction
j-- is a subset of Java and is the language that our example compiler translates to JVM
code. It has a little less than half the syntax of Java. It has classes; it has int s, boolean s,
char s, and String s; and it has many Java operators. The `j' is in the name because j-- is
derived from Java; the `--' is there because j-- has less functionality than does Java. The
exercises in the text involve adding to this language. We add fragments of Java that are not
already in j--.
B.2 j--Program and Its Class Declarations
A j-- program looks very much like a Java program. It can have an optional package state-
ment, followed by zero or more import declarations, followed by zero or more type declara-
tions. But in j--, the only kind of type declaration we have is the class declaration; j-- has
neither interfaces nor enumerations.
We may have only single-type-import declarations in j--; it does not support import-on-
demand declarations (for example, java.util.* ). The only Java types that are implicitly
imported are java.lang.Object and java.lang.String . All other external Java types
must be explicitly imported.
For example, the following is a legal j-- program:
packagepass;
importjava.lang.Integer;
importjava.lang.System;
publicclassSeries{
publicstaticintARITHMETIC=1;
publicstaticintGEOMETRIC=2;
privateinta;//firstterm
privateintd;//commonsumormultiple
privateintn;//numberofterms
publicSeries(){
this(1,1,10);
}
299
 
Search WWH ::




Custom Search