Introduction to Interactive Programming
by Lynn Andrea Stein
A Rethinking CS101 Project

Java Charts

Expression

Every Java expression has both a type and a value. A Java expression is made up of exactly one of the following.

literal This is a literal expression. It represents a literally-expressible value. It is of a primitive type, String, or null.
name This is a name expression. The type of this expression is the type the name was declared to have. Its value is the value stored in the corresponding shoebox or referenced by the corresponding label. Name expressions include fields, local variables, and parameters as well as classNames.
this This is an object self-reference expression. It may only appear in non-static method or field definitions.

This expression refers to the object whose method is being executed (field is being defined). Its type is the class of the object, and its value is the object itself.

( expression ) This is a parenthetical expression. It is used to disambiguate expressions by grouping things together. Its value and type are the same as those of the contained expression.

prefixOperator expression

expression postfixOperator

expression1 infixOperator expression2

booleanExpression ? expression1 : expression2

These are operator expressions. They include unary operations such as - and ++, binary operations such as *, >, and =, and the ternary conditional operator.
( typeName ) expression This is a cast expression. typeName is any type name, including primitive type, class name, interface name, or array type, but not void. expression is any expression. The parentheses are required.

The value of this expression is the value of expression. The type of this expression is typeName. (Not all cast expressions are legal.)

objectReferenceExpression . methodName ( argList )

super . methodName ( argList )

This is a method invocation expression. objectReferenceExpression is any expression whose value refers to an object. argList is empty or a list of comma-separated expressions. Parentheses must be present even if the argument list is empty.

Expression type and value are return type, value of method.

objectReferenceExpression . fieldName

super . fieldName

This is a field access expression. objectReferenceExpression is any expression whose value refers to an object. argList is empty or a list of comma-separated expressions.

The expression type is the declared type of the field. The value of the expression is the shoebox/ label value.

new ClassName ( argList ) This is an instance creation expression. ClassName is any class name. argList is empty or a list of comma-separated expressions. The parentheses must be present even if the argument list is empty.

The expression's type is ClassName. Its value is a newly created instance of ClassName.

arrayExpression [ integerExpression ] This is an array access expression. arrayExpression is any expression whose type is an array type.integerExpressionis an expression with intgral type.

If arrayExpression is of type type[], this expression is of type type and its value is that of the integerExpressionth shoebox or label.

new typeName [ integerExpression ] This is an array creation expression. typeName is any type name, including primitive type, class name, interface name, or array type, but not void. integerExpressionis an expression with integral type.

Expression type is typeName[], i.e., array of typeName. Its value is a new array of typeName, i.e., integerExpression shoeboxes or labels suitable for typeName.


© 1999 Lynn Andrea Stein

This chapter is excerpted from a draft ofIntroduction to Interactive Programming In Java, a forthcoming textbook from Morgan Kaufmann Publishers, Inc. It is a part of the course materials developed as a part of Lynn Andrea Stein's Rethinking CS101 project at the MIT AI Lab and the Department of Electrical Engineering and Computer Science at the Massachusetts Institute of Technology.

Questions or comments:
<cs101-webmaster@ai.mit.edu>

Last modified: Fri Sep 12 09:39:11 1997