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
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
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
02/22/2023 Rivka Scheinberg Post in Garbage Collection,Implementing an Interface,Oracle Exams Leave a Comment on Inheritance Hierarchy and Enclosing Context – Nested Type Declarations Inheritance Hierarchy and Enclosing Context – Nested Type Declarations Inheritance Hierarchy and Enclosing Context A non-static member class can extend another class and implement interfaces, as any normal class. An inherited field (or method) in a non-static member subclass can hide a field (or method) with the same name… Continue Reading
10/22/2022 Rivka Scheinberg Post in Implementing an Interface,Non-Static Member Classes,Oracle Exams Leave a Comment on Non-Static Member Classes – Nested Type Declarations Non-Static Member Classes – Nested Type Declarations 9.3 Non-Static Member Classes Declaring Non-Static Member Classes Non-static member classes are inner classes—that is, non-static nested classes— that are defined without the keyword static as instance members of either a class, an enum type, or a record class. Non-static… Continue Reading
09/22/2022 Rivka Scheinberg Post in Implementing an Interface,Oracle Exams,Static Member Types Leave a Comment on Static Member Types – Nested Type Declarations Static Member Types – Nested Type Declarations 9.2 Static Member Types Declaring Static Member Types Static member types can be declared in top-level type declarations, or within other nested types. For all intents and purposes, a static member type is very much like a top-level type. A… Continue Reading
07/22/2022 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 Exponential Functions – Selected API Classes Exponential Functions – Selected API Classes Exponential Functions Click here to view code image static double pow(double d1, double d2) Returns the value of d1 raised to the power of d2 (i.e., d1d2). Click here to view code image static double exp(double d) Returns the exponential… Continue Reading
05/22/2022 Rivka Scheinberg Post in Implementing an Interface,Oracle Exams Leave a Comment on Comparing String Builders – Selected API Classes Comparing String Builders – Selected API Classes Comparing String Builders String builders implement the Comparable<StringBuilder> interface and can be compared lexicographically, analogous to String objects (p. 447). Click here to view code image int compareTo(StringBuilder anotherSB) Here are some examples of string builder comparisons: Click here to… Continue Reading
10/22/2021 Rivka Scheinberg Post in Determining the Range,Implementing an Interface,Oracle Exams Leave a Comment on Accessing Members in the Enclosing Class – Nested Type Declarations Accessing Members in the Enclosing Class – Nested Type Declarations Accessing Members in the Enclosing Class Example 9.11 illustrates how a local class can access members in its enclosing class. The top-level class TLCWith2LCS declares two methods: nonStaticMethod() and staticMethod(). Both methods define a local class each: NonStaticLocal at (1)… Continue Reading
08/22/2021 Rivka Scheinberg Post in Garbage Collection,Implementing an Interface,Oracle Exams Leave a Comment on Instantiating Non-Static Member Classes – Nested Type Declarations Instantiating Non-Static Member Classes – Nested Type Declarations Instantiating Non-Static Member Classes An instance of a non-static member class can only exist when associated with an instance of its enclosing class. This means that an instance of a non-static member class must be created in the context of… Continue Reading