07/22/2024 Rivka Scheinberg Post in Determining the Range,Garbage Collection,Implementing an Interface,Non-Static Member Classes,Oracle Exams,Static Member Types Leave a Comment on Incidental Whitespace – Selected API Classes Incidental Whitespace – Selected API Classes Incidental Whitespace So far the lines in the text blocks have all been left-justified. This need not be the case. Indentation can be used if desired. However, one needs to be careful as incidental whitespace from each line is removed… Continue Reading
05/22/2024 Rivka Scheinberg Post in Determining the Range,Oracle Exams Leave a Comment on Implementing an Interface – Nested Type Declarations Implementing an Interface – Nested Type Declarations Implementing an Interface The following syntax can be used for defining and instantiating an anonymous class that implements an interface specified by the interface name: Click here to view code image newinterface_name<optional_parameterized_types>() {member_declarations } An anonymous class provides a single interface… Continue Reading
03/22/2024 Rivka Scheinberg Post in Garbage Collection,Oracle Exams Leave a Comment on Instantiating Anonymous Classes – Nested Type Declarations Instantiating Anonymous Classes – Nested Type Declarations Instantiating Anonymous Classes The discussion on instantiating local classes (see Example 9.12) is also valid for instantiating anonymous classes. The class AnonClassClient in Example 9.14 creates one instance at (11) of the non-static anonymous class defined at (5) by calling… Continue Reading
02/22/2024 Rivka Scheinberg Post in Implementing an Interface,Oracle Exams Leave a Comment on Accessing Declarations in Enclosing Context – Nested Type Declarations Accessing Declarations in Enclosing Context – Nested Type Declarations Accessing Declarations in Enclosing Context Member declarations and access rules for local classes (p. 512) also apply to anonymous classes. Example 9.15 is an adaptation of Example 9.9, Example 9.10, and Example 9.11. It illustrates what members can be declared… Continue Reading
01/22/2024 Rivka Scheinberg Post in Non-Static Member Classes,Oracle Exams Leave a Comment on Garbage Collection – Object Lifetime Garbage Collection – Object Lifetime 10.1 Garbage Collection Efficient memory management is essential in a runtime system. Storage for objects is allocated in a designated part of the memory called the heap, which has a finite size. Garbage collection (GC) is a process of managing… Continue Reading
11/22/2023 Rivka Scheinberg Post in Oracle Exams,Static Member Types Leave a Comment on Using Qualified Name of Nested Types – Nested Type Declarations Using Qualified Name of Nested Types – Nested Type Declarations Using Qualified Name of Nested Types The qualified name of a (static or non-static) member type includes the names of the enclosing types it is lexically nested in—that is, it associates the member type with its enclosing types. In Example… Continue Reading
08/22/2023 Rivka Scheinberg Post in Determining the Range,Garbage Collection,Oracle Exams Leave a Comment on Accessing Members in Enclosing Context – Nested Type Declarations Accessing Members in Enclosing Context – Nested Type Declarations Accessing Members in Enclosing Context Static member classes do not have a this reference, as they do not have any notion of an enclosing instance. This means that any code in a static member class can only directly access static… Continue Reading
08/22/2023 Rivka Scheinberg Post in Determining the Range,Implementing an Interface,Oracle Exams Leave a Comment on Determining the Range – Selected API Classes Determining the Range – Selected API Classes Determining the Range We are often interested in generating random numbers in a particular range. For example, the following code will return a random number in the interval [0, 10]: Click here to view code image number = generator.nextInt(11); //… Continue Reading
06/22/2023 Rivka Scheinberg Post in Determining the Range,Non-Static Member Classes,Oracle Exams Leave a Comment on Generating the Same Sequence of Pseudorandom Numbers – Selected API Classes Generating the Same Sequence of Pseudorandom Numbers – Selected API Classes Generating the Same Sequence of Pseudorandom Numbers The way in which we have used the pseudorandom number generator up to now cannot guarantee the same sequence of pseudorandom numbers each time the program is run. This is because the pseudorandom… Continue Reading
04/22/2023 Rivka Scheinberg Post in Determining the Range,Oracle Exams,Static Member Types Leave a Comment on Accessing Members in Enclosing Context – Nested Type Declarations Accessing Members in Enclosing Context – Nested Type Declarations Accessing Members in Enclosing Context An implicit reference to the enclosing object is always available in every method and constructor of a non-static member class. A method or constructor can explicitly specify this reference using a special form of the… Continue Reading