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
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
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
06/22/2022 Rivka Scheinberg Post in Determining the Range,Oracle Exams Leave a Comment on Reading Characters from String Builders – Selected API Classes Reading Characters from String Builders – Selected API Classes Reading Characters from String Builders The following methods can be used for reading characters in a string builder: Click here to view code image char charAt(int index) From the CharSequenceinterface (p. 444).void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies characters… Continue Reading
12/22/2021 Rivka Scheinberg Post in Determining the Range,Garbage Collection,Oracle Exams Leave a Comment on Instantiating Local Classes – Nested Type Declarations Instantiating Local Classes – Nested Type Declarations Instantiating Local Classes Clients outside the scope of a local class cannot instantiate the class directly because such classes are, after all, local. A local class can be instantiated in the block in which it is defined. Like a local… 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