JavaHyperText Skip to main content JavaHyperText and Data Structures David Gries, with help from many Home Java HyperText Style Guide Eclipse 0. Create project 1. Show line numbers 2. Import preferences for automatic formatting 3. Reset layout 4. Syntax help 5. Open 2 files 6. ToDO comments 7. JUnit testing 8. Assert statement 9. Generating javadoc 10. Red square: terminating programs 11. Remove/add imports 12. Use UTF-8 character encoding API and strings 1. API documentation 3. Using Strings Explain constructs Introduction 1. Assignment statement 2. New-expression 3. Method calls 2. Try-statement Exceptions 1. Output of thrown exceptions 2. Throwable objects 3. Try-stmt/propagation 4. Throw-statement 5. Throws-clause 6. Hints Abstract classes interfaces Iterator & Iterable Program correctness Loop invariants 1. Introduction 2. Developing loops 3. Finding an invariant Stepwise refinement Recursion Intro to recursion Recursion on linked lists Recursion on trees Backtracking Hashing DFS BFS Shortest path JavaHyperText The links in the navigation bars above take you to webpages with videos / tutorials on many aspects of Java and data structures. Type a word into the Filter field below and only entries whose titles contain that word will be displayed. Filter: Type one of these words into the Filter field to see a table of contents for that topic: Java Data structures Other anonymous function casts classes constructors generics interfaces I/O JUnit testing types variables graphs hashing linked list sorting trees complexity concurrency polymorphism recursion study habits testing % remainder operation \ escape character += -= *= /= %= (compound assignment operators) See this one-page pdf file. ++ -- (increment and decrement operators)e See this one-page pdf file. <> See diamond <>. = versus == See this pdf file. @Override An 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. But you are not required to put it on a method that overrides another. 2-3 tree See pdf file. absolute path, a in file system See I/O (first entry). 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 data type (ADT) A type whose methods are declared in an abstract way, without regard to implementation. See this pdf file. 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 component. 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. 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 acyclic A graph is acyclic if it does not contain a cycle. See this pdf file. ad-hoc polymorphism ad hoc Read this pdf file. See also polymorphism. adjacency list, adjacency matrix These are two ways to represent a graph. See this pdf file. adjacent Two nodes of a graph are said to be adjacent if there is an edge connecting them. See this pdf file. 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. algorithmic complexity 1. Introduction: pdf file. 2. Basic step, including the notion of constant time: pdf file. See also pdf file. Exercises on calculating the number of basic steps. To come String catenation is not a basic step: pdf file. get(k) in a LinkedList is not a basic step: pdf file. Basic steps in executing insertion sort: pdf file. 3. Definition of O(...): pdf file. Exercises of proving f(n) in O(g(n)). pdf file. Some time-complexity classes: pdf file. Shortcuts in deciding on complexity classes: pdf file. Why you should never write f(n) = O(g(n)): pdf file. 4. Amortized time, introduced using ArrayList as an example: pdf file. 5. Sorting provides a lot of examples of calculating time and space requirements. This table gives the basic sorting algorithms and links to pdf files for them: Algorithm Worst time Expected time Space insertion sort selection sort O(n^2) O(n^2) O(1) heap sort O(n log n) O(n log n) O(1) merge sort O(n log n) O(n log n) O(n) quick sort O(n^2) O(n log n) O(n) quick sort improved O(n^2) O(n log n) O(log n) comparison sorts no better than O(n log n) annotation Something like @Override. See this one-page pdf file. Annotations in a JUnit 4 testing class: See this pdf file. amortize Merriam-Webster's online dictionary tells you that amortize means to write down gradually to extinguishment the cost of (as asset) by periodic charges to expense or profit and loss. That is too abstract for us. This pdf file explains amortization, using class ArrayList as an example. This pdf file uses amortization in estimating the time complexity of a hashing algorithm. anonymous class This two-page pdf file explains what an anonymous class is and how to instantiate it. anonymous function - lambda Anonymous functions were introduced in Java version 8. An anonymous function is a function declared without a name —it has just parameters, a return type, and a body. These first items are for those who don't know about interfaces: 1. Short definition and explanation: pdf file. 2. Use an anonymous function to check that an assertion is thrown: pdf file. 3. Use an anonymous function to sort an array or an array segment: pdf file. 4. Use an anonymous function to sort an ArrayList or LinkedList ---any List: pdf file. 5. Use an anonymous function to listen to button click in a GUI: pdf file. 6. Anonymous functions and functional interfaces: pdf file. DemoClassD.zip. DemoClassE.zip. 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. The specification of the API for Java version 1.9 appears here: docs.oracle.com/javase/9/docs/api/index.html?overview-summary.html. 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 you 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. application programmer interface See API 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, type argument See type argument 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 Explanation of how arrays are used and implemented in Java: pdf-file. Creating ragged/jagged multidimensional arrays, in which each row can have a different number of elements: pdf-file. Sort using an anonymous function: array pdf file, List or ArrayList or LinkedList pdf file array, creating a generic array See this: pdf-file array initializer The expression new int[]{3, 5, 4} creates an int array of size 3, with elements 3, 5, and 4. The notation {3, 5, 4} is called an array initializer. For more info, see this pdf-file. assert statement The assert statement has the form assert ; To execute it, evaluate the ; if false, throw an AssertionError, which will generally cause the program to abort. Read this to learn about its use and how to turn on its execution. assertEquals assertFalse assertTrue Method assertEquals(expected-value, computed-value) is used in a JUnit testing class to test whether a computed value is correct. Never use an assert statement for this purpose. One can also use methods assertTrue(computed value) and assertFalse(computed value). See webpage. assertThrows Method assertThrows(exception.class, anonymous-function) is used to tell whether a call of the anonymous function throws the exception. See webpage. 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 The assignment statement has the form = ; 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 and store its value in the . For more information see the 2.5-minute video on this webpage. See this pdf file for a history of = for equality and why the change to the assignment operator caused confusion. See this pdf file for the compound assignment operators += -= *= /= %=. atomic action A section of a program that must be executed as an indivisible sequence of operations; no other process, or thread, can interrupt or interfere with its execution. autoboxing, auto-unboxing, autowrapping In certain situations, like the declaration-assignment Integer d= 5; the integer 5 will automatically be wrapped in a new object of type Integer. This is called autoboxing, although autowrapping would have been more appropriate. Similarly, in the declaration-statement int k= d; the integer in d will be auto-unboxed so that it can be stored in k. Autoboxing and auto-unboxing can take place between each primitive type and its wrapper class. Read the pdf file at entry wrapper class. B-tree See pdf file. back door Refers to referencing a synchronized object without synchronizing. Can lead to efficiencies, but should be used with care and only by someone knowledgeable with concurrency. pdf file. Demo code: BackDoor.zip backpointer Consider a path (p, p1, p2, ...) in a graph. A backpointer for a node in the path is the previous node. Thus, p1's backpointer is p and p2's backpointer is p1. Backpointers are used in Dijkstra's shortest path algorithm. backtracking Backtracking is a technique for recursively solving a problem by choosing one possible solution but then removing that choice (this is the backtracking) and trying another if it doesn't work. This webpage contains two videos that give a good example of backtracking. bag, set, unibag A bag is a bunch of elements with duplicates allowed. The bag {25, 5, 25, 10} has size 4 because it contains 5, 10, and 25 twice. Think of it as a representation of a bag containing 2 quarters, a dime, and a nickel. A set is a bunch of elements with no duplicates allowed. The set {25, 5, 10} has size 3. Some people call a bag a multi set or multiset, since an element can occur multiple times in a bag. That goes against the usual use of an adjective to restrict, e.g. we can restrict the dogs we are considering by talking about old dogs or brown dogs. Instead of set and multiset, we should use bag and unibag. balanced tree A tree of size n is balanced if its height is O(log n). Different properties of a tree can ensure that it is balanced. pdf file. Proof that the height of a height-balanced binary tree with n nodes is O(lg n). pdf file. base 2, 8, 10, and 16 The natural numbers 0, 1, 2, ... can be represented in different bases or radixes. See this pdf file. base case In a recursive method, a base case is case (i.e. values for the method's parameters) in which a recursive call is not needed. See this pdf file. basic step An expression or statement whose evaluation or execution takes roughly the same amount of time no matter what the values being manipulated. Adding two int values is a basic step. Summing the values in an array is not —the time required depends on the size of the array. See this pdf file. binary number system The system for writing natural numbers 0, 1, 2, ... using bits 0 and 1. See this pdf file. binary operator An operator with two operands. Examples are addition and multiplication, 5 + 2 and 6 * 8. See also ternary operator and unary operator. binary search See this pdf file. You might find this banquet speech, which pokes fun while giving a message, interesting: Eliminating the chaff. binary search tree (BST) See this pdf file. binary tree A tree in which each node has at most two children. pdf file. Proof that a height-balanced binary tree with n nodes has height O(log n). pdf file. bipartite graph A graph is bipartite if its nodes can be partitioned into two sets such that no edge connects two nodes in the same set. See this pdf file. 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. This pdf file also describes the marks of a boolean tyro, a novice, beginner. 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. bounded buffer A place to store items that may be put in and taken out at different rates by different threads. See Concurrency. bounded wildcard See generics. bound function A function that is used in proving that a loop terminates or that a recursive function terminates. For loops: still to come. For recursive functions: pdf file. break statement See this pdf file. The break statement is used most often to terminate execution of a switch statement. breadth first search (bfs) An algorithm to traverse all nodes of a graph. See the tutorial on DFS BFS. bucket In hashing, an element of the hash table is sometimes called a bucket. See this webpage for a tutorial on hashing. byte A primitive type whose values are integers in the range –2^7 .. 2^7 – 1, or -128..127. See this pdf file for an explanation. Byte, class A wrapper class for type byte. bytecode Java bytecode is the virtual machine language into which Java programs are compiled. See this pdf file. cache A memory cache for a CPU (Central Processing Unit) is a small hardware component that contains copies of some main memory locations so that future requests for them can be served faster than retrieving them from main memory. The terms spacial locality and data locality refer to the use of data elements within relatively close storage locations. An algorithm with high spacial locality will have higher cache performance than one with low spacial locality. See this pdf file for a longer explanation with more examples of caches. Here's a use of a cache in software to make a recursive method more efficient: pdf file. calculate elapsed time To calculate the time that any method or operation takes do two things: Place this local declaration just before the code to be timed: long startTime= System.currentTimeMillis(); Then, place this code just after the code to be timed: long time= System.currentTimeMillis() - startTime; That gives you the elapsed time in milliseconds. call stack At runtime (during execution of a Java program), the call stack contains a list of frames for method calls that have been started but have not yet completed. The list is actually a stack because it follows the LIFO principle. This webpage discusses the call stack. casts 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. 1. Casting between types char and int: pdf file. 2. Casting among the number types byte, short, int, long, float, and double: pdf file. 3. Casting with classes, called class casts: pdf file. 4. 3.75-minute video on casting with interfaces: webpage. 5. Compile-time casting rule (defines when a cast is syntactically OK): pdf file. 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. 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". chaff, eliminating You might find this banquet speech on eliminating the chaff entertaining as well as educational: pdf file. chaining In hashing, there are essentially two ways to maintain the elements of the set being implemented using hashing. In chaining, each bucket of the hash table is a linked list containing the values that hashed to that bucket. In open addressing, each bucket is either null or an element of the set begin maintained. See this webpage for a tutorial on hashing. char A primitive type whose values are single characters, like 'h'. This pdf file explains type char and the unicode representation of characters. This pdf file explains more about code points and what to watch out for when characters not in type char are used in Strings. Character, class A wrapper class for type char. Christmas Halloween Why did I receive a Christmas card on Hallowen? pdf file 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 on the method header in which the exception is thrown. The video on this webpage explains it. circular linked list See this pdf file. class definition, class declaration A class definition (or declaration) 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. It is a blueprint for objects of the class. This pdf file explains describes the basic class definition and explains how we draw objects. 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. classes, subclasses, and objects 1. Class definition or declaration: a blueprint for objects, describing what is in them. A. Format of the class definition and what an object of the class looks like: pdf file. B. Using keyword extends to define subclasses (and superclasses); C. What a subclass object looks like: pdf file. D. Subclasses and the "is-a" relation: one-page pdf file. E. Definition of inheritance: see inheritance. F. Class Object, the superest class of them all, and the class hierachy: page 2 of pdf file. G. Overriding a method and the use of "super.": pdf file. H. Keyword this eveluates to a pointer to the object in which it occurs; the user of "this.": pdf file. 2. Constructor. Purpose: To initialize fields of an object when it is created in order to make the class invariant true. A. The new-expression. Syntax: new . 2-minute video on this webpage. B. Rule: initialize superclass fields before subclass fields. pdf file. C. Syntactic rule: a constructor that you write must start with a call on another constructor; if it doesn't, the call super(); is inserted. pdf file. D. How to call another constructor using super(...) or this(...). pdf file. E. If a class C does not have a constructor, this one is inserted: C() {}. pdf file. 3. The class/interface as a type. A. A class name can be used as a type. Its values are pointers to objects of that class (and also null). A variable of some class-type C contains a pointer or reference to an object of type C. B. An interface name can also be used as a type. Its values are pointers to objects of any class C (and also null) that implements the interface. C. The compile-time reference rule determines whether a component reference like p.v or p.m(...) is syntactically correct: pdf file. D. The bottom-up or overriding rule determines which method will be called at runtime: pdf file. 4. Abstract class. Make a class abstract so that it cannot be instantiated —objects of the class cannot created. Make a method in an abstract class abstract so that subclasses must override it. The first video on this page, 3.5-minutes long, explains abstract classes and methods. 5. Interfaces. An interface provides a way to ensure syntactically (at compile-time) 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. A. 2.4-minute tutorial that explains interfaces: second video on this page. B. How an interface defines an abstract data type (ADT): pdf file. C. Multiple inheritance and the diamond problem: pdf file 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 (pointers to) 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 (pointers to) objects of class JFrame. class container See container, for a class. class, generic See generics. 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 Javadoc 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 of the type is a pointer or reference to an object. class variable Same as a static variable. clone, cloning To clone means to make an exact duplicate of. This pdf file introduces the topic. Later pdf files will explain how to clone in Java. code coverage Eclipse JUnit testing to show code coverage: pdf file. code point An integer that represents a character in the Unicode system. For characters in Java type char, it is the integer that is returned when a character is cast to int. This pdf file explains type char and the unicode representation of characters. This pdf file explains more about code points and what to watch out for when characters not in type char are used in Strings. coercion A type conversion is the conversion of a value from one type to another, e.g. from type int to type double. An explicit conversion, e.g. (float) 5 or (int) 5.3, is called a cast. An implicit conversion performed by the Java system is often called a coercion rather than a cast. An example is the coercion of int 5 to double value 5.0 in the assignment double d= 5; collision In hashing with open addressing, if an element e to be put into the set hashes to a bucket h and an element is already in bucket h, a collision is said to have occurred. The collision is solved using some form of probing, usually linear or quadratic probing. See this webpage for a tutorial on hashing. coloring A coloring of an undirected graph is an assignment of a color to each node such that no two adjacent nodes get the same color. One application is a map, in which the nodes are countries and adjacent countries are connected by an edge. See this pdf file for the greedy graph coloring algorithm. More on the four-color theorem later. comment, javadoc comment Java has 3 kinds of comment, shown below. // 1. This comment starts with two slashes and ends at the end of the line. /* 2. This possibly multi-line comment starts with slash star and ends with: */ /** 3. This special possibly multi-line comment, called a javadoc comment, starts * with slash star star and ends with: */ The term, "javadoc" stands for "java documentation". Place a javadoc comment BEFORE each class, method, and field declaration in order to describe or specify that declaration. These comments can be extracted by an app called javadoc in order to provide a specification of a class. Eclipse also makes use of javadoc comments, e.g. hover the mouse over a method call and the spec of the method will pop up. In writing javadoc comments, help format them nicely by using the html tag to end a line. Comparable, compareTo Interface java.lang.Comparable, or java.lang.Comparable, has one abstract method: CompareTo(ob). It is supposed to return a negative int, 0, or a positive int depending on whether this object "comes before", equals, or "comes after" its parameter ob. See this pdf file. comparison sort A comparison-sorting algorithm is a sorting algorithm that uses only comparisons (like b < c) to sort. The worst-case time using comparison sorting to sort an array of size n is O(n log n). Read about comparison sorting in this pdf file. 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. For more information, read this this two-page pdf file. compile-time, compiletime The time at which the compiler checks the syntax of a program and, if there are no errors, translates the program into an equivalent machine language program, ready to be executed (or run). compile-time casting rule This rule determines whether a cast (class-name) object is syntactically correct and can be compiled. See this pdf file. compile-time reference rule This rule determines whether a component reference like p.v or p.m(...) is syntactically correct. See this pdf file. complete, full, perfect binary tree A complete binary tree has no holes: Every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. In a full binary tree, each node has 0 or 2 children. A perfect binary tree is a full binary tree in which all leaves are at the same level. Thus, a perfect binary tree is a complete binary tree in which every level is completely filled. Still to come: a pdf file with examples of such trees. complete graph A complete graph has as many edges as possible. A complete directed graph with n nodes has n(n-1) edges. A complete undirected graph of n nodes has half as many: n(n-1)/2. 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. compound assignment operator See pdf file. concatenate, concatenation Same as catenate. concurrency Concurrency refers to having more than one thread of execution in a program, allowing different parts of a program to execute in parallel. 1. Cores and processing units, processes and threads: pdf file 1. Click here for a definition of thread-safe. 2. Learn about race conditions (pdf file 2) and deadlock (pdf file 3). 3. Class Thread and interface Runnable. pdf file 4. 4. Some methods of class Thread. pdf file 5. 5. Intro to synchronized statements and methods. pdf file 6. * Example of using the back door: pdf file. Demo code: BackDoor.zip * 20-sec video of Christopher Caspersen's new outhouse (2018): video.mov. * Warning: Don't know what you're doing? Synchronize all accesses to an object: bottom of page 2 of pdf file 6. 6. Intro to wait(), notify(), and notifyAll(). pdf file 7. Warning: Don't know what you're doing? Don't use notify(). pdf file 8. Code that illustrates the above using a dropbox (bounded buffer of size 1). boundedBufferDemo.zip. 7. Implementing a bounded queue in an array and a bounded buffer. pdf file 9. 8. Java classes that provide for concurrency. pdf file 10. 9. What's a daemon thread? pdf file 11. conditional expression. Uses ? and : An expression of the form ? : . It is a ternary operator: it has three operands. To evaluate it, evaluate the ; if it is true, use the value of as the value of the conditional expression; otherwise, use the value of as the value of the conditional expression. Here are examples: 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 connected Two nodes of a graph G are connected if there is a path in G whose endpoints are the two nodes. Graph G is connected if each pair of nodes in it is connected; otherwise, G is disconnected. A graph of 1 node and no edges is connected. A graph with two nodes and no edges is disconnected. See this pdf file. conjunction The proper word for and, the boolean operator &&. See this pdf file. connected component A connected component of graph is a subgraph that is connected and that has no node or edge in common with the rest of the graph. A graph, then, consists of the collection of its connected components. Here's a simple example. Consider a graph with 3 nodes and no edges. Then each node is a connected component, and the graph has 3 connected components. constant In Java, a variable whose value cannot be changed is called a constant. To declare such a variable, use keyword final, as in this example: public static final double PI= 3.1415926535897932384626433832795; 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. constant time An operation or method takes constant time if the time it takes to carry it out does not depend on the size of its operands. For a more detailed explanation, with examples, see this pdf file. constructors A method that is declared with the basic form: ( ) { ... } The purpose of a constructor is to initialize the fields of a new object of class so that the class invariant is true when the object is created. See this pdf file for: (1) Rule: initialize superclass fields before subclass fields. (2) Syntactic rule: a constructor that you write must start with a call on another constructor; what call is inserted if it is not present. (3) How to call another constructor using super or this. (4) What constructor is inserted if a class does not have a constructor. HERE is a summary of all important points concerning constructors: pdf file. 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 ( ) 2. As a call of another constructor in the same class: this();. 3. As a call of a constructor of the superclass: super();. constructor call, default If (and only if) the first statement of the body of a constructor is not a constructor call, this one is inserted: super(); constructor, default If (and only if) a class definition does not contain a constructor, this one is inserted: public () {} 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. continue statement Execution of the statement "continue;" terminates execution of the loop body in which it occurs. See pdf file. core A component on a chip that contains a "processing unit", which can execute sequences of instructions. See pdf file. counting sort A linear-time sorting algorithm that is not a comparison sort. It works by counting (and then using) the number of times each value occurs in the array being sorted. See pdf file. creators, observers, mutators An alternative to the conventional getter/setter terminology: pdf file. CPU Central Processing Unit. See pdf file. critical section Part of a program that accesses resources shared by two or more threads. To avoid a race condition, have it executed as an atomic action —with no other processing accessing or changing the resources while the critical section is being executed. In Java, this is usually done using a synchronized statement or method. See this pdf file. cuckoo hashing A form of hashing with open addressing in which methods contains and remove take constant time in the worst case. Its name is inspired by the actions of the European cuckoo bird. pdf file. cycle A path in a graph is a cycle if it contains at least one edge and its first and last nodes are the same. The cycle is simple if the first node appears exactly twice. See this pdf file. DAG A directed acyclic graph is called a DAG. Summary: pdf file. More detail: pdf file. David Gries's PhD genealogy —it's a DAG and not a tree: pdf file. Topological sort, an algorithm to produce an ordering of a DAG in which the source of each edge precedes its sink: pdf file. Proof that a directed graph in which each node has indegree > 0 contains a cycle: pdf file. daemon thread See pdf file. data structure An organization or format for storing and managing data, usually to make some operations efficient. Here is an example. Consider type list: the collection of lists of values like (3, 5, 2) together with operations to add and delete elements, to search for them, etc. Java class ArrayList is an example of a data structure that implements type list. The singly linked list, as described in this pdf file, is another example of a data structure that implements type list. data type Another word for type. See this pdf file. deadlock Deadlock occurs when a group of processes (or threads) can't make progress because they need a resource that another process in the group has locked. See pdf file. debugging The process of looking for and fixing an error once it has been determined that there is an error. decimal number system The system for writing natural numbers 0, 1, 2, ... using digits 0, 1, ..., 9. See this pdf file. default package The package that is used for a class file that is not placed in an explicitly named package. See this pdf file for an explanation. 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. degree The degree of a node u in an undirected graph is the number of edges for which u is an endpoint. See this pdf file. The degree of a node in a tree is the number of children it has. Thus, a leaf has degree 0. See this pdf file. dense A graph is dense if the number of edges is close to the maximum. A graph is sparse if the number of edges is close to the minimum. These terms are not well defined in the literature. So we use these definitions: A graph with n nodes is dense if the number of edges is proportional to n*n; it is sparse if the number of edges is O(n). A map of a city is generally a sparse graph because the number of edges leaving each intersection is generally 4 or less. 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. depth first search (dfs) An algorithm to traverse all nodes of a graph. See the tutorial on DFS BFS. depth first search walk (dfs walk) An extension of dfs to simulate walking around a graph. See the tutorial on DFS BFS. depth, level, width, and height in a tree The depth of a node is the length of the path from the root to the node. Thus, the root is at depth 0 and its children are at depth 1. The level of a node is 1 + (its depth). The height of a node is the length of a longest path from that node to a leaf. The height of an empty tree is -1. The height of a non-empty tree is the height of its root. The width of a tree at depth d is the number of nodes with depth d. The width of a tree is the maximum of its widths at all depths. See this pdf file. deque A deque (double-ended queue, pronounced "deck") is a list that supports insertion and deletion at both ends. See this pdf file. descriptor, of a method The method signature plus the return type. diamond <> An abbreviation in a new-expression like new ArrayList<>(). See this pdf file. digraph A directed graph is sometimes called a digraph. diamond problem A problem that occurs when there is multiple inheritance: a method is inherited from two or more classes or interfaces, and a decision must be made on which inherited method is used. See this pdf file. dropbox A bounded buffer of size 1, used to illustrate synchronization among threads. See Concurrency. Code that uses a dropbox to illustrate use of notify() and notifyAll(). boundedBufferDemo.zip. Edsger W. Dijkstra 1. The Jarník/Prim/Dijkstra algorithm for constructing a minimum spanning tree: pdf file. 2. Shortest path algorithm: webpage. 3. Dijkstra's paper containing the shortest path and minimum spanning tree algorithms: pdf file. 4. Implementing the JPD algorithm: pdf file. 5. Using the JPD spanning-tree algorithm to construct a maze: pdf file. Java: mazeGeneration.zip 6. Dining philospher's problem: pdf file. dining philosophers A problem invented by Edsger W. Dijkstra to illustrate deadlock. See this pdf file. directed graph A graph whose edges are directed from one node to another. See this pdf file. disconnected unconnected A graph is connected if there is a path between any pair of nodes. Otherwise, it is disconnected. One sometimes sees the word unconnected used for disconnected, but the proper word is disconnected. See this pdf file. disjunction The proper word for or, the boolean operator ||. See this pdf file. do-loop (do-statement) See this pdf file for an explanation of the do-loop. double A primitive type whose values are written in scientific notation, 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. doubly linked list See this pdf file. downcast, upcast; narrowing, downward, widening, upward cast A widening cast is a cast of an expression to a wider type, e.g. int to double. Widening casts will be done automatically when necessary. A narrowing cast is a cast of an expression to a narrower type, e.g. double to int. Narrowing casts must be called for explicitly. Suppose an object is looked at from the perspective of some class or interface C. An upcast, or upward cast, is a cast of that object to one of the superclasses or superinterfaces of C. Upcasts will be done automatically when necessary. A downcast, or downward cast, is a cast of that object to one of the subclasses or subinterfaces of C. Downcasts casts must be called for explicitly. DrJava A simple IDE for Java. WE NO LONGER USE IT BECAUSE IT HAS NOT BEEN UPDATED TO USE JAVA 11. Instead, we use the command-line application JShell. DrJava's Interactions Pane made it extremely easy to try out different things, because you could type any statement or expression and have it executed or evaluated immediately. For example, you could write: f= new javax.swing.JFrame(); to create a new JFrame object and store (a pointer to) it in f. We used to teach Java in the first programming course at Cornell. Students didn't know they needed a method main until week 10 of the course, because we relied on the Interactions Pane and JUnit testing for all work. You can still download DrJava from www.drjava.org. Dutch National Flag An algorithm to sort an array that has at most three different values: pdf file. -ea -da ea stands for enable the assert statement; da for disable the assert statement. It is a VM (Virtual Machine) argument that can be used to turn on execution of the assert statement. To disable the assert statement, remove -ea or replace it with -da --the default is -da . Read about it here. Eclipse: an Integrated Development Environment (IDE) We use the IDE Eclipse for developing, testing, and running Java programs. Use the Eclipse menu in the navigation bar at the top of the page to learn more. To learn more about IDEs in general, read this Wiki page. elegance As one definition of elegance, the online Unabridged Merriam-Webster Dictionary give this: scientific precision, neatness, and simplicity. We strive for elegance when developing programs, for only with elegance can we hope to achieve programs that are understandable and correct. Tony Hoare said: "Inside every large program is a small program struggling to get out." Edsger Dijkstra said: "Beauty is our business."" else-part, then-part In an if-else statement if (b) S1 else S2 , statement S1 is called the then-part and S2 is called the else-part. endpoint For an edge {u, v} of an undirected graph, u and v are the endpoints of the edge. See this pdf file. enhanced for statement Java's formal terminology for a foreach loop. See foreach loop. enum, or enumeration type An enum class provides constants (static final variables), like Coin.PENNY and Coin.NICKEL. The basics: pdf file. Adding fields and methods to an enum class: pdf file. enumeration, enumerate An enumeration of a collection of values (set, bag, list, etc) is simply a list of them. To enumerate the values is to produce them one by one. Consider the set {4, 7, 2}. A set is unordered, so an enumeration of its values is a list of them, in an arbitrary order. Here's one example: 4, 2, 7. To enumerate the values in the set is to produce its values one by one. For example, to enumerate the set above, produce 4, then 3, then 7. This is explained in the first video in the tutorial on Iterator/Iterable equals The call b.equals(c) on function equals in class Object returns true iff b == c is true, i.e. b and c evaluate to null or to the same pointer ---they point to the same object. Equals should sometimes be overridden in a class to define what equality means for that class. This pdf file tells you how to do it, and here are some .java files to demo with: equalsDemo.zip 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: \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. exponentiation Calculating b^n for integer n ≥ 0 in O(log n) time recursively and iteratively: pdf file. Java code exclusive OR, XOR The exclusive OR of two bits b and c yields 1 if the bits are different and 0 if they are the same: 1 XOR 1 = 0, 0 XOR 0 = 1, 1 XOR 0 = 1, 0 XOR 1 = 1. In a similar manner, one defines the XOR of two boolean values: T XOR T = F, F XOR F = F, T XOR F = T, F XOR T = F. Here, one can see that b XOR c is just b ≠ c, and there's no need to introduce XOR. 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. factory A factory builds things. In OO parlance a factory method returns an object of a class, building a new one if necessary (using a new-expression). This pdf file pdf file explains. Fibonacci numbers The sequence 0, 1, 2, 3, 5, 8, 13, ... in which each one (except the first two) is the sum of the previous two. Calculating Fibonacci numbers: pdf file. A paper by Parmanand Singh on the ancient history of Fibonacci numbers: pdf file. Fibonacci numbers in architecture and nature: pdf file (to come). Uses of Fibonacci numbers in computer science: pdf file (to come). 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 written in scientific notation, 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. Follower minus First Formula for calculating how many values are in a range like m..n. The first element of the range is m. The last one is n and its follower is n+1. So the number of integers in the range m..n is the Follower (n+1) minus the First (m), for n+1-m. See the first video on ranges on this page. forest A set of zero or more trees. An undirected graph is a forest if each of its connected components is a tree. See this pdf file on spanning trees. 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. four color theorem The four-color theorem: this pdf file. Sipka's paper on Kempe's flawed proof: this pdf file. Gonthier's paper on the Coq proof: this pdf file. 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. This webpage discusses the frame for a call. function A method that is declared with the basic form: ( ) { ... } 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: . ( ) 2. for a non-static function: . ( ) where the evaluates to the name of an object that contains the function to be called. Both "." and "." can be omitted if the call appears in a place in which the function can be called without them. functional interface An interface that has exactly one abstract method. Default methods have an implementation and are not abstract. If an interface declares an abstract method overriding one of the public methods of class Object, that method also doesn't count toward the interface's abstract method count since any implementation of the interface will have an implementation from Object or elsewhere. Use the annotation @FunctionalInterface on a functional interface you write to ensure that it indeed one. See this pdf file. generalize Math and computer science often involve the process of generalizing statements. By generalizing a statement, we mean including new situations, or states. For example, one can generalize the statement "2^4 is even" to "2^k is even, for all positive integers k". A video on generalization appears here on this JavaHyperText webpage. generic class See generics. generic method See pdf file. generics 1. History of generics in Java and what generics means: pdf file. 2. Introduction to generic classes: pdf file. 3. Introduction to generic methods: pdf file. 4. Creating a generic array: pdf file. 5. Why ArrayList is not a subclass of ArrayList