Object-oriented concepts and definitions
This webpage contains definitions of Java concepts and constructs. It is not complete, but you can find most of what you want to know here. It also cannot give complete, rigorous definitions of everything ---for that, you have to read the Java language specification. But it covers the most usual cases and gives you a good conceptual view of objects and classes.
Many of the explanations are given in pdf files. They are never more than two pages long, and most are one page. This should make it easy to read and digest any topic.
- %
- remainder operation
- /
- escape character
- += -= *= /= %= (compound assignment operators)
- See this one-page pdf file.
- ++ -- (increment and decrement operators)
- See this one-page pdf file.
- @Override
- Annotation that is placed on a method that is supposed to override a method in a superclass or interface. It's a good idea to use it, for it tells you there is an error if the method doesn't actually override another method, perhaps because of a typo.
- abstract class
- A class that is declared with modifier abstract.
The main feature is that the class cannot be instantiated ---if class C is abstract, the expression new C(...) is syntactically illegal.
The first video on this page is a 3.5-minute tutorial that explains abstract classes and methods. - abstract method
- A method declared with modifier abstract in
an abstract class. Its body is replaced by a ";".
Its main feature is that any non-abstract
subclass must overridde.
The first video on this page is a 3.5-minute tutorial that explains abstract classes and methods. - access modifier
- Java has four levels of access to components. In order of accessibility, they are: public, protected, package (no modifier), and private. The table below shows the access to components of a class depending on the access modifier on that compoent. For example, a component that is protected can be referenced from within the class, from other classes in the same package, and from a subclass.
- actual parameter
- A term used for argument (of a method call). The term should never be used because it is confusing, especially because the adjective "actual" tends to be omitted and then it is just parameter, which is even more confusing.
- anonymous class
- This two-page pdf file explains what an anonymous class is an how to insantiate it.
- API
- Application Programmer Interface. A set of tools (in Java, packages of classes and interfaces) for building "application software". You are building application software when you write a Java program.
modifier | class | package | subclass | world |
---|---|---|---|---|
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
no modifier | Y | Y | N | N |
private | Y | N | N | N |
The specification of the API for Java version 1.8 appears here: docs.oracle.com/javase/8/docs/api/. Visit this site often to learn about some class (like String, or JFrame) and its methods.
- apparent class
- We don't use this terminology. When see it, ignore it. It is not needed.
- applet
- An applet is a Java program that contains a subclass of java.awt.Applet or javax.swing.JApplet. It can appear on web pages.
- application
- A Java application is a program that has a class that contains a
static procedure defined like this:
public static void main(String[] pars) {...}
An application can be executed without using an IDE. One creates a jar-file that contains all the classes of the program and uses it as a stand-alone program.
- argument
- An expression that occurs within the parentheses of a method call.
The following call has two arguments: x+y and y+w:
min(x+y, y+w)
The number of arguments must equal the number of parameters of the method that is being called, and the type of each argument must be the same as or narrower than the type of the corresponding parameter. - argument, variable number of, in a call
- See this pdf file to see how to allow a variable number of arguments in a call
- array
- This pdf-file explains how arrays are used and implemented in Java.
This pdf-file explains how to create ragged/jagged multidimensional arrays, in which each row can have a different number of elements. - assertion
- A true-false statement about the variables in a program that is placed as a comment at a particular place in the program to indicate that the true-false statement is true at that place. See also precondition and postcondition.
- assignment statement
- binary operator
- An operator with two operands. Examples are addition and multiplication, 5 + 2 and 6 * 8. See also ternary operator and unary operator.
- block
- A sequence of statements, local variable declarations, and local class declarations enclosed in braces { }.
- boolean
- A primitive type whose values are true and false. See this pdf file for an explanation.
- Boolean, class
- A wrapper class for type boolean.
- bottom-up rule
- This is also called the overriding rule. When looking for a method in an object that is appropriate for a method call, start from the bottom of the object and look upward. This rule ensures that an overriding method will be called (if present) rather than an inherited one.
- byte
- A primitive type whose values are integers in the range –2^8 .. 2^8 – 1. See this pdf file for an explanation.
- Byte, class
- A wrapper class for type byte.
- cast
- A cast converts a value from one type to another.
Example: the cast (double)(5+6) converts the value of the expression 5+6 to double format.
This pdf file explains casting between types char and int.
This pdf file explains casting among the number types byte, short, int, long, float, and double.
This pdf file explains casting with classes, called class casts.
This webpage contains a 3.75-minute video on casting with interfaces. - catenate, catenation
- To link together, to place side by side. Suppose b and c are of type String. Then operation b + c denotes catenation. Its resulting value is a new String that contains the characters of b followed by the characters of c.
The assignment statement has the form <variable> = <expression> ;
To be syntactically correct, the
type of the expression must be the same as or narrower than the type of the variable. To execute the assignment statement, evaluate the <expression> and store its value in the <variable>. For more information see the 2.5-minute video on this webpage.
See this pdf file for the compound assignment operators += -= *= /= %=.
If only one of b and c are of type String, then b + c still denotes catenation, and the non-String operand is changed into its String representation before the catenation is done. If the non-String operand is of some class-type, its toString method is called to obtain its String representation.
The simplest way to get a String representation of any expression is to catenate it with the empty String. For example, "" + (68 + 2) evaluates to a String that contains "70".
- char
- A primitive type whose values are single characters, like 'h'. This pdf file explains type char and the unicode representation of characters.
- Character, class
- A wrapper class for type char.
- checked exception
- Java "checks" all throwable objects except those of class Error and RuntimException. A checked exception has to be handled in one of two ways: (1) catch it in a catch-block or (2) put a throws-clause throws <class-name> on the method header in which the exception is thrown. This video on this webpage explains it.
- class
- A class definition defines the format of objects (or
instances or folders) of the class —it defines the methods and fields that
go in each object of the class. This pdf file explains how we draw an object of a class.
The class definition also defines the static variables (class variables) and static methods (class methods).
A class can be used as a type. If C is (the name of) a class, then C v; declares a variable v that contains either null or the name of (or pointer to) an object of class C. - class, apparent
- We don't use this terminology. If you see it being used, ignore it.
- class as a type
- A class name can be used as a type. Its values are the names of objects of that class (and also null). For example, the declaration JFrame j indicates that variable j can contain values that are the names of objects of class JFrame.
- class container
- In order to provide an easy-to-understand introduction to classes and objects, at runtime, we view a class as a container that contains the objects of the class and the static components of the class. See this one-page pdf file for an explanation.
- class invariant
- The collection of meanings and constraints on the fields of a class
that describe the valid states of all instances of the class before
and after each method is called. The class invariant should appear
as comments on the declarations of the fields.
A constructor should truthify the class invariant. Each method body can assume that the class invariant is true and should terminate with the class invariant true. - class method
- See static method.
- class, nested
- See nested class.
- class, real
- See real class.
- class, static
- See nested class.
- class type
- A type that is the name of a class or interface. Its values are the names of (pointers to) objects
of that class, and null.
Also called reference type because a value ot the type is a pointer or reference to an object. - class variable
- Same as a static variable.
- compiler
- A (Java) compiler is a program that checks the syntax of a program, and, if the program is syntactically correct, translates it into (the Java virtual) machine language, so that it can be run, or executed. This is called compiling the program, and it happens at compiletime. The Eclipse IDE calls the compiler often as you are editing a program, and it happens so fast that you don't notice it.
- compile-time reference rule
- This rule determines whether a component reference like p.v or p.m(...) is syntactically correct. See this pdf file.
- component
- A component of a class is a variable, method, or inner class that is declared in the class or is inherited from the superclass.
- concatenate, concatenation
- Same as catenate.
- conditional expression
- An expression of the form <boolean-expression> ? <expression-1> : <expression-2>. It is a ternary operator: it has three operands. To evaluate it, evaluate the <boolean-expression>; if it is true, use the value of <expression-1> as the value of the conditional expression; otherwise, use the value of <expression-2> as the value of the conditional expression. Here are examples:
- constant expression
- An expression of a primitive type or type String that can be evaluated at compile-time and replaced by its value. If two or more such String expressions have the same value, only one String object is created for all of them. See this pdf file.
- constructor
- A method that is declared with the basic form:
- <access modifier> <class-name> ( <parameter-declarations> )
{ ... }
The purpose of a constructor is to initialize the fields of a new object of class <class-name> so that the class invariant is true when the object is created. See also constructor call. - constructor call
- A call of a constructor. The purpose of a constructor call is to initialize fields of a newly created object so that the class invariant is true. There are three
ways to call a constructor —the last two ways may appear only as
the first statement of a constructor body:
1. In a new-expression. It has the form <class-name> ( <arguments> )
2. As a call of another constructor in the same class: this(<arguments>);.
3. As a call of a constructor of the superclass: super(<arguments>);. - constructor call, default
- If (and only if) the first statement of the body of a constructor is not a constructor call, Java automatically inserts this one: super();
- constructor, default
- If (and only if) a class definition does not contain a constructor, the following
one is automatically inserted in the class:
public <class-name>() {}
- container, for a class
- Conceptually, we think of all the objects of a class together with its static components being housed in a container, a box. This conceptual view, along with the inside-out rule, helps explain the concept of "static" and how the declaration corresponding to a variable reference is found. This view may give the feeling that all objects and static components reside in contiguous places in memory, but that is not the case. Just think of the container as a conceptual aid, not an implementation device. See this pdf file for an example.
- default values
- Fields (both static and non-static) have default values (if they are not initialized), as follows: numeric-type fields: 0; boolean fields: false; char fields: '\u0000'; and class-type fields: null. Local variables do not have initial default values and must be assigned before referenced.
- deprecate
- To deprecate means to lessen in value. Some classes and methods within classes in the Java API package have been deprecated because they have been superceded by newer ones that do a better job. You can still use the deprecated entities, but it is better if you don't.
- do-loop (do-statement)
- See this pdf file for an explanation of the do-loop.
- double
- A primitive type whose values are scientific numbers, e.g. 3.46E–4. Each value occupies 64 bits. See this pdf file for an explanation.
- Double, class
- A wrapper class for type double.
- dynamic type
- We don't use this terminology. If you see it being used, ignore it.
- enhanced for statement
- Java's formal terminology for a foreach loop. See foreach loop.
- enums, or enumeration types
- An enum class provides constants (static final variables), like Coin.PENNY and Coin.NICKEL.
This two-page pdf file gives you the basics.
This two-page pdf file shows you how to add fields and methods to an enum class. - Error, class
- A subclass of class Throwable; its objects and those of its subclasses should not be caught and processed, as opposed to those of class Exception, which may be caught and processed. See the 3.2-minute video on throwable objects here.
- escape character \
- The escape character \ is used to write characters that cannot appear directly in a String. Here are examples; there are others:
5 < 4 ? 1+6 : 3 evaluates to 3 since the boolean-expression is false
5 > 4 ? 1+6 : 3 evaluates to 7 since the boolean-expression is true
\n —new-line character
\\ —backslash character
\" —double quote character
\' —single quote character (you can use ' in a String, but as a character, write '\''
- Exception, checked
- See checked exception.
- Exception, class
- A subclass of class Throwable; its objects and those of its subclasses may be caught and processed, as opposed to those of class Error, which shouldn't be caught. See the 3.2-minute video on throwable objects here.
- exception handling
- When something like a division by 0 happens, or any exception is "thrown", the flow of control of a program is altered. This important topic of exception handling is covered in tutorials here.
- expression
- In Java, each expression has a type, which depends on the type of its operations and operands. Evaluation of the expression yields a value of that type.
For information on increment/decrement expressions ++ and --, see this pdf file.
Look here for constant expressions. - extends clause
- A clause, extends C, put on a class definition to indicate that the defined class is a subclass of class C and that C is a superclass of the defined class. The subclass inherits all components defined in and inherited by the superclass.
- field
- A variable belonging to a class (static field) or instance (non-static field).
- final
- A variable declared with keyword final cannot be assigned after its initial assignment. For example, the following declaration of PI in class Math includes keyword final so that PI cannot be changed:
public static final double PI= 3.141592653589793;
A class that is declared with keyword final cannot be extended ---cannot have a subclass.
- float
- A primitive type whose values are scientific numbers, e.g. 3.46E–4. Each value occupies 32 bits. See this pdf file for an explanation.
- Float, class
- A wrapper class for type float.
- folder
- Same as object or instance.
- foreach loop
- See this pdf file for an explanation of the foreach loop.
You can enable the use of the foreach statement on your own collection class by implementing interfaces Iterator and Iterable. This tutorial shows you how in less than 15 minutes of video: webpage. - for-loop
- See this pdf file for an explanation of the for-loop.
- formal parameter
- We use the term parameter (of a method) instead of formal parameter and argument (of a method call) instead of actual parameter. The terms formal parameter and actual parameter should never be used because they are confusing, especially because the adjectives tend to be forgotten and then there is no difference in the terms.
- frame for a call
- When a method is called, a frame is created for the call. This frame
contains
(1) the name of the method,
(2) a program counter, which indicates which statement to execute next,
(3) a scope box, which contains the name of the class or object in which the method resides,
(4) the parameters of the method, and
(5) the local variables of the method. - function
- A method that is declared with the basic form:
- <access modifier> <return-type> <function-name> ( <parameter-declarations> ) { ... }
- Execution of the body of the function must terminate by executing a return statement, giving an expression whose value is to be returned. A call on a function is an expression (and thus yields a value).
- function call
- A function call is an expression, so it can be placed wherever an
expression (of the appropriate type) can be placed. Its form is one
of:
1. for a static function: <class-name> . <function-name> ( <arguments> )
2. for a non-static function: <expression> . <function-name> ( <arguments> )
where the <expression> evaluates to the name of an object that contains the function to be called. Both "<class-name>." and "<expression>." can be omitted if the call appears in a place in which the function can be called without them. - getter method
- A non-static function whose purpose is to retrieve a value from the object in which the method appears —the value is usually in a field of the object. If the field to be retrieved is named xab, by convention, the name of the getter method is getXab. But the convention need not be followed.
- header, of a method
- The part of a declaration of a method that gives the access modifiers, prefixes like static, the return type or void, the method name, and the parameter declarations delimited by parentheses. Thus, it is the complete method declaration except for the method body.
- hiding fields and static components
- Fields are not overridden but are hidden. This is explained in this pdf file.
Static components are not overridden but are hidden. This is explained in this pdf file. - Hoare triple
- Something of the form {Q} S {R} where Q and R are assertions and S is a statement It has the meaning: Execution of S in a state in which Q is true is guaranteed to terminate, and when it does, R is true.
- implements clause
- The implements clause, implements <interface-name>, on a class indicates that the class overrides all abstract methods declared in the interface. As of the latest Java version, the class need not override methods that have defaults.
- import statement
- The import statement has one of the forms:
import <path>.<class-name>; // import a particular class
import <path>.*; // import all classes in the package
where the <path> is a path of the API package (e.g. javax.swing) or a path to a directory on your hard drive that represents a package of classes. It is placed as the first statement of a file that contains a class definition in order to indicate that the class may refer to the classes in the directory given by the <path>. - infix operator
- An operator that is written between its two operands. E.g. +, as in 5 + 6. See also prefix operator and postfix operator.
- inheritance
- A subclass inherits all the instance fields and methods available in its superclass. This means that each instance of the subclass contains not only the instance fields and methods defined in it but also the instance fields and methods defined in an inherited by the superclass.
The Java spec uses "inheritance" slightly differently: private fields are not inherited. However, the private fields DO appear in each object of the subclass, so we think the Java use of "inherited" is wrong and will continue to say that ALL components are inherited.
Here's an analogy. Suppose a 16-year-old son's parent's die. He inherits their money. But the money is put in a Trust, and, he cannot touch the money until he is 18. That's like saying the private field appears in each object of the subclass but it is private.
- inner class
- A non-static class that is declared within another class.
This pdf file explains why nested classes are useful.
Study this example of the use of a static nested class before reading the next example: pdf file.
Here is a simple but realistic example of the use of an inner class: pdf file.
- inside-out rule
- A rule, used in most programming languages, that indicates how to determine what a reference to a variable or a method means (which declaration it refers to). It is explained in this pdf file.
- instance
- An instance of a class is an object or manila folder of a class; instance, object, and manila folder are synonyms.
- instance method
- A method that is defined without modifier static in a class. A copy of the method resides in each instance of the class.
- instanceof
- Operation <pointer-to-object> instanceof <class-name> yields true iff the object is an object of class <class-name> or of a subclass of <class-name>. See page 2 of this pdf file for a full explanation.
- instance variable
- A variable that is defined without modifier static in a class. Also called a field. A copy of the variable resides in each object of the class.
- instantiate
- To create an instance of. So, evaluation of a new-expression new C(...) instantiates class C, producing a new instance, or object, of the class.
- int
- A primitive type whose values are integers
in the range –2^31 .. 2^31 – 1, together with its operations +, -, *, *, and % (remainder).
See this pdf file for an explanation. - Integer, class
- A wrapper class for type int.
- integral types
- The Java primitive types whose values
are integers: byte, short, int, long,
and char.
See this pdf file for an explanation of char.
See this pdf file for an explanation of byte, short, int, and long. - interface
- An interface provides a way to ensure syntactically (at compiletime)
that a class implements certain methods. The interface defines the
methods abstractly (without bodies), and the class definition then
includes an implements clause to
indicate that it will define the methods.
The second video on this page is a 2.4-minute tutorial that explains interfaces. - jagged array
- See ragged array.
- literal
- A Java denotation of a value. Here are examples of literals: 354, 3.56F, true, 'c', and "peace".
See this pdf file for literals of the number types (like int and float).
See this pdf file for literals of type char - local variable
- A variable that is declared within the body
of a method. It does not have a default value and must be assigned before it can be referenced. The scope of a local variable is from its declaration to the end of the block in which it is declared.
Principle: Place a local variable as close to its first use as possible. Do not simply declare all local variables at the beginning of a method. FOLLOW THIS PRINCIPLE. - long
- A primitive type whose values are integers in the range –2^63 .. 2^63 – 1. See this pdf file for an explanation.
- Long, class
- A wrapper class for type long.
- loops
- Java has four different kinds of loops. Here are one-page pdf files that explain each of them:
for-loop, while-loop, do-loop, foreach loop.
You can enable the use of the foreach statement on your own collection class by implementing interfaces Iterator and Iterable. This tutorial shows you how in less than 15 minutes of video: webpage. - manila folder
- Same as object or instance.
- Math, class
- Class Math, in package java.lang, contains a bunch of mathematical functions —e.g. sin(...), tan(...), ceil(...)— as well as the constants PI and E.
- method
- A set of instructions to be carried out. A method is analogous to a recipe in a cookbook. Java has three kinds of method: function, procedure, and constructor.
- method body
- A method consists of a method header followed by the method body, which has the form: { <sequence of statements/declarations> }. When the method is called, its body is executed.
- method call
- An expression or statement that ends up executing the method body.
See function call, procedure
call, and
constructor call. It is important
to understand how a method call is executed. Its execution is performed in four steps:
1. Push a frame for the call onto the call stack;
2. Assign argument values to the parameters;
3. Execute the method body;
4. Pop the frame for the call from the call stack (and, if a function, put the function value onto the call stack).
- method header
- See header, of a method.
- method name
- The name of the method, defined in the method header.
- method main
- A Java program becomes an application when a static procedure main is defined that has one parameter, of type String[]. The application can be started without having to have an IDE around. To start execution, this method main is called.
- method signature
- The method name together with the types of its parameters. For example, one method in class Math has signature min(int, int).
- method specification
- The specification of a method defines what the method does. It is used to understand how to write calls on the method. It must be clear, precise, and thorough, and it should mention all parameters, saying what they are used for. It is a contract between the programmer who wrote the method and users of the method. It may be given in terms of a precondition and postcondition. The reference gives details on specs for the different kinds of methods:
- methods allowing a variable number of arguments in a call
- See this pdf file to see how to allow a variable number of arguments in a call.
- narrower type
- Below, each line gives a series of types, beginning with the narrowest
type and proceeding to the widest type:
byte --> short --> int --> long --> float --> double
char --> int --> long --> float --> double
subclass --> superclass
See cast to find complete information on casting. - nested class
- A class that is declared within another class.
This pdf file explains why nested classes are useful.
Here is a simple but realistic example of the use of a static nested class: pdf file.
Here is a simple but realistic example of the use of an inner class: pdf file. - new-expression
- The new expression has the form new <constructor-call>. Evaluation of the new-expresion creates a new object and has as its value the name of (pointer to) the created object. See a full, detailed explanation of it in a 2-minute video on this webpage.
- non-static nested class
- See inner class.
- non-static method
- Same as instance method.
- non-static variable
- See instance variable.
- null
- A value that means "the absence of an object name". If a reference like null.b or a method call like null.m(...) is attempted at runtime, a "null pointer exception" happens.
- Number types
- The Java primitive types byte, short, int, long, char, float, and double.
See this pdf file for an explanation of char.
See this pdf file for an explanation of byte, short, int, long, float, and double. - object
- An instance of a class, also called a folder. Each object of a class contains the non-static fields and methods defined in and inherited by the class. See class. This pdf file explains how we draw objects.
- Object, class
- The superest class of them all: any class that does not explicitly extend another class automatically extends class Object. This pdf file explains how we draw objects.
- object type
- Same as class type.
- operator precedences
- See precedence of operators
- overloading
- A method name is overloaded if there are two methods with the same name but different signatures. For example, class Math contains static functions with signatures min(int, int) and min(double, double).
- override
- A method that is inherited from the superclass can be overridden by redeclaring it in the subclass. The bottom-up rule (or overriding rule) ensures that the overriding method will be called, rather than the inherited one.
Fields are not overridden but are hidden. This is explained in this one-page pdf file.
Static components are not overridden but are hidden. This is explained in this one-page pdf file.
- package
- A package consists of the classes that are contained in a specific directory on your hard drive (or the API packages, like javax.swing and java.lang).
- parameter
- A variable that is declared within the parentheses of the header of a method.
- partition, of an object
- A place within an object for the components declared in a particular class. See this pdf file for an explanation.
- parameter declaration
- A parameter declaration occurs within the parentheses of the header of a method. It has the form <type> <variable-name>.
- postcondition
- An assertion that indicates what is to be true at the end of execution of a method body —or, more generally, of any sequence of statements.
- postfix operator
- An operator that is written after its operand. E.g .factorial is a postfix operator: 7 ! . Also, ++ and -- can be used as postfix operators (see this pdf file) See also infix operator and prefix operator.
- precedence of operators
- Standard mathematics gives precedence to multiplication * over addition +, so that the expression 2 + 3 * 5 is evaluated as if it were parenthesized like this: 2 + (3 * 5). Here is the Java precedence table: pdf file.
- precondition
- An assertion that indicates what is to be true at the beginning of execution of a method body —or, more generally, of any sequence of statements.
- prefix operator
- An operator that is written before its operand. E.g. unary minus is a prefix operator: - (4 + 2). Also, ++ and -- can be used a prefix operators (see this pdf file). See also infix operator and postfix operator.
- primitive type
- A type that is fully integrated into Java, i.e.
one that is not defined by a class definition.
See this pdf file for an explanation of primitive type char.
See this pdf file for an explanation of the other primitive number types: byte, short, int, long, float, and double.
See this pdf file for an explanation of type boolean. - private
- An access modifier. A variable or method that is declared with this modifier can be referenced only within the class in which the declaration occurs.
- procedure
- A method that is declared with the basic form:
- <access modifier> void <function-name> ( <parameter-declarations> ) { ... }
- A call of a procedure is a statement.
- procedure call
- A procedure call is a statement. Its form is one
of:
1. for a static procedure: <class-name> . <function-name> ( <arguments> ) ;
2. for a non-static procedure: <expression> . <function-name> ( <arguments> ) ;
where the <expression> evaluates to the name of an object that contains the procedure to be called. Both "<class-name>." and "<expression>." can be omitted if the call appears in a place in which the procedure can be called without them. - promoting a value
- Same as casting it to a wider type, done automatically in Java when necessary. See narrower type.
- protected
- An access modifier; the variable or method that is declared protected can be referenced from within the class, from other classes in the same package, and from a subclass.
- public
- An access modifier: the variable or method that is declared with this modifier can be referenced everywhere.
- ragged array
- This pdf-file explains how to create ragged/jagged multidimessional arrays, in which each row
can have a different number of element .
But if you are not familiar with arrays in Java, read this first: pdf-file. - real class
- We don't use this terminology. If you see it anywhere, just ignore what you are reading (e.g. an old prelim question).
- reference rule
- The compile-time reference rule determines whether a component reference like p.v or p.m(...) is syntactically correct. See this pdf file.
- reference type
- See class type.
- remainder %
- For c and d of type int, the expression c % d gives the remainder whern c is divided by d.
- repetend
- Repetend means "the thing to be repeated". We use it for the body of a loop.
- return statement
- In a procedure, a return statement has the form
- return;
- In a function, a return statement has the form
- return <expression>;
- Execution of the return statement terminates execution of the method body in which it occurs and, in the case of a function, returns the value of the <expression> as the value of the function call.
- runtime
- The time when a program is being executed, or run, as opposed to compiletime, when the program is being compiled.
- scope
- The scope of a variable is the set of statements in which it can be referenced. For a parameter, it is the body of the method in which the parameter is declared. For a local variable, it is from its declaration to the end of the block in which it is declared.
- scope box
- A box within the frame for a method call that contains the name of the class (for a static method) or object (for an instance method) in which the method resides.
- semantics
- Syntax has to do with grammatical correctness, semantics with meaning. We cannot talk about the semantics of a part of a sentence of a language that is not syntactically correct. The semantics of a Java expression or statement defines how it is evaluated or executed. For example, the semantics of the if-statement statement if ( <boolean-expression> ) <statement> is: first, evaluate the <boolean-expression>; then, if it is true, execute the <statement>.
- setter method
- A non-static procedure whose purpose is to store a value in a field of the object in which the method resides. If the field is named xab, by convention, the name of the setter procedure is setXab.
- shadowing a variable
- shadowing refers to declaring two variables with the same name with overlapping scopes. Given a reference to such a variable, the inside-out rule indicates to which of the declarations the reference refers. For example, suppose a class has a field x and a method m within the class has a parameter x. That parameter, shodows field x ---every reference to x within the method refers to the parameter.
- short
- A primitive type whose values are integers in the range –2^15 .. 2^15 – 1. See this pdf file for an explanation.
- Short, class
- A wrapper class for type short.
- signature
- See method signature.
- specification, of a class
- A description of what a class is for. Generally speaking, it indicates what an instance of the class represents.
- specification, of a method
- See method specification.
- statement-comment
- A comment that is a specification of the following lines of code. See this one-page pdf file for an explanation.
- static
- See static method and static variable. See this pdf file for an explanation.
- static field
- Same as static variable. See this pdf file for an explanation.
- static method
- A method that is declared with attribute static. There is only one copy of the method. See this pdf file for an explanation of static.
- static nested class
- A static class that is declared within another class.
This pdf file explains why nested classes are useful.
Here is a simple but realistic example of the use of a static nested class: pdf file.
- static type
- We don't use this terminology. If you see it being used, ignore it.
- static variable
- A variable declared in a class definition with attribute static. There is only one copy of the variable. It is created when execution of the program starts. See this pdf file for an explanation of static.
- String, class
- The values of class String are objects that contain sequences of characters.
- subclass
- Class SC is a subclass of class C, and C is the superclass of SC, if the definition of class SC has an extends clause extends C. This means that every instance of class SC inherits all the components of class C.
- super
- A keyword that is used in two ways.
(1) super.m(...) calls method m within the object in which it appears. To determine which version of m is called, use the bottom-up (overriding) rule, but start looking in the partition above the one in which the method call appears.
(2) super(...); can appear as the first statement in a constructor; it calls a constructor of the superclass ---which one is called depends on the types of the arguments within the parentheses..
<variable> = <expression> ;
(1) this is an expression; it evaluates to the name of (pointer to) the object in which it appears. For example, this.x is a reference to a field x of the object.
(2) "this(...);" can appear as the first statement in a constructor; it calls another constructor in this class ---which one is called depends on the types of the arguments within the parentheses.
Watch a 3.2-minute video on throwable objects here.
Watch a 3.2-minute video on throwable objects here.
Watch a 5-minute video on interpreting the output of an uncaught thrown object here.
Watch a video on the throw-statement and a video on catching and throwing the exception further here.
try <statement>
catch (<class-name1 e1>) <catch-statement1>
...
catch <class-namen en>) <catch-statementn>
where each of the <class-names> is a throwable class. There can also be a "finally clause", which we don't discuss. The try-statement is explained, with videos, here and also in this pdf flle.
- two's complement notation
- A way of representing an integer as a sequence of bits. Used in most computers today. See this explanation: pdf file.
- type
- A set of values together with operations on them. E.g.the integers, together with operations +, -, *, /.
Java has primitive types and class types. - unary operator
- An operator with one operand. In the following examples, unary minus and factorial each have one operand:
- (6+2), 6! . Unary prefix operators have highest precedence and are evaluated from right to left. E.g. - + - 8 + 5 is evaluated as (-(+(- 8))) + 5. See also ternary operator and binary operator. - variable
- A name with an associated value. Sometimes viewed as a named box with the value in the box. In Java, a variable has a type, which defines the set of values that the box can contain. In Java, there are four kinds of variable: parameter, local variable, instance variable (or field), and class variable (or static variable).
- variable declaration
- The basic form of a variable declaration is <type> <variable-name>. Depending on the kind of variable being declared, there may be modifiers. See parameter, local variable, instance variable, and static variable.
- void
- A java keyword used to indicate that a method is a procedure and does not return a result. See procedure.
- while-loop (while-statement)
- See this pdf file for an explanation of the while-loop.
- wider type
- See narrower type.
- wrapper class
- Each of the primitive types of Java has an associated wrapper class. For example, the wrapper class for type int is Integer. Each instance of the wrapper class contains, or wraps, one value of the primitive type, thus allowing a primitive type value to be viewed as an object. In addition, the wrapper class provides functions for manipulating values of the primitive type and may also include a few constants. Read wrappers.pdf