Uploaded by Amaan Khan

230

advertisement
#separator:tab
#html:true
str.split(delimeter)This method allows you to split a string into an array of substrings based on a specified delimiter(char). It returns an array of strings.
str.charAt(index)This method returns the character at a specified index within a string. It can be used to access individual characters within a string.
str.substring(start index, end index), what if end index is omitted? This method extracts a portion of a string based on the specified starting and ending indexes. It returns a new string that represents the extracted substring. if end index is omitted it defaults to the end of the string
String > int <ul><li>To convert a String to an int, use the Integer.parseInt(String) method.</li></ul>
int > String  To convert an int to a String, you can use the Integer.toString(int) method or the String.valueOf() method.
Character.toUpperCase(char) method to convert a character to uppercase. static method part of Character class 
"""\\"""prints backslash
\'  prints single quotes
" \"" "prints double quote
char literals are enclosed in single quotes. T or Ftrue
what is %c for format string?character
what is %d for format stringdecimal int
%f for format stringfloating point/double
how to specify you want to print a float to n significant figures in format string,%.nf
%s in format stringstring
%n newline in format string
"flag ""-"" for print f"left aligns output, e.g %-10s, left aligns string and if string.length() < 10 pads remaining with spaces to right
what does width do in printf; e.g %10swidth = min. no. of digits; if string.length() < width, output is padded with spaces (width- string.length())
Casting int > double.double d1 = n1; where n1 is already an int, <br>or<br>double d2 = (double) n1; casting conversion
what is explicit casting? when is it done?"data type of higher size annot be assigned to lower type without casting; e.g int i1 = d1; , where d1 is alr an double <span style=""background-color: rgb(170, 0, 0);"">(this results in a complile time error)<br></span><br>explicit casting: i2 = (int) d1 everything beyond decimal point of d1 is truncated; eg. if d1 = 4.8, <br>(int) d1 = 4<br><br>"
char > int (ASCII)<br>"char c = 'A';<br>int x = c; <span style=""background-color: rgb(170, 0, 0);"">prints ACSII of A in decimal which is 65</span>"
int > char "int x = 65;<br>char c = (char) x; <span style=""background-color: rgb(170, 0, 0);"">prints 'A' as 65 in ASCII is char 'A'</span>"
char > double "char c = 'A';<br>double d1 = c; <span style=""background-color: rgb(170, 0, 0);"">prints ASCII value of 'A' as a double = 65.0</span>"
double > char"double d1 = 65.0<br>char c = (char) d1; <span style=""background-color: rgb(170, 0, 0);"">prints A as 65.0 = 'A' in ASCII</span>"
str.length()return length of string;
str.split('\s')Split the string on whitespace into a list/array of strings
str.trim()remove any whitespace at beginning or end
Post Increment : i++, and Pre Increment : ++iIncrement Value of Variable After Assigning, First Increment Value and then Assign Value.
str1.equals(str2)compares whether the contents of str1 and str2 are the same;
format of Java ternarty op (?):var x = (conditon) ? value if true : value if false;
what does  a switch statement do?"<ul><li>multiple choice Q for ur program, checks if given var matches options(cases)</li><li>each option/case is a possible ans, if var matches one of these ans, code underneath that case will run. </li><li>if no <span style=""background-color: rgb(170, 0, 0);"">break;</span> after case program will fall through/ run the code for all following cases till a break is encountered/ or end of case.</li><li>can include a default case, which is a catch all for when var does not match any of the other cases, placed at end when no other case is true;</li></ul>"
continue;"skips remaining statements of <span style=""background-color: rgb(170, 0, 0);"">THIS</span> iter. in loop body and proceeds with next iter. of loop."
Character.isAlphabetic(char)used to determine whether char is alphabetic or not, can be used with str.charAt(index);
Character.isDigit(char)used to check whether char is a number.
"str.toCharArray():<br>e.g = <br>String str = ""Hello"";
<br>char[] charArray = str.toCharArray();""returns a char array where each letter in the string is seperated into a char in the array;<br>the example above produces output ; <span style=""font-weight: 600;"">['H', 'e', 'l', 'l', 'o']</span>"
"str.indexOf(char) or <span style=""background-color: rgb(170, 0, 0);"">str.indexOf(substring);</span>""returns index/pos of first occurance of char or <span style=""background-color: rgb(170, 0, 0);"">returns index of first char in substring;</span> returns -1 if value not found"
declaring an array:<pre>datatype[] arrayName = new datatype[size];</pre>
"Initialize the array: You can initialize the 2D array with default values or with specific values using a nested loop or by assigning values to each element of the array, <span style=""background-color: rgb(170, 0, 0);"">what is the syntax?</span>"<pre>arrayName[rowIndex][columnIndex] = value;</pre>
Access the elements of the 2D array:<pre>value = arrayName[rowIndex][columnIndex];</pre>
what is method overloadingMethods of the same name can be declared in the same class, as long as<br>they have different sets of parameters
how does a compiler disunguish between overloaded methods"Compiler distinguishes overloaded methods by their <span style=""background-color: rgb(170, 0, 0);"">signatures:</span><br>A combination of the method’s name and the number, types and order of its parameters, but not its return type."
declaring an ArrayList :<pre>ArrayList<objectType> listName = new ArrayList<>();</pre>
declaring 2d Arrays:<pre>datatype[][] arrayName = new datatype[rows][columns];</pre>
array.length number of rows in array
array[row number].lengthno. of columns in row
enum.values()method returns an array of enum type containing all the constants
Sb.reverse()reverses string buffer
sb.append(str/char to add)adds str or char to existing string buffer
Sb.setCharAt(int index, char c)replaces char at index of string buffer to char c, can be used to swap chars + replace.
arrlist.add(int index, obj)add obj to arrlist at index, if index is omiited adds obj to end of list.
arrlist.contains(obj)returns true if obj in list, false otherwise.
arrlist.indexOf(obj)returns index  of first occurance of obj in arrlist, is obj not in list returns -1.
arrlist.size()returns no. of elements in list
arrlist.isEmpty()returns true if empty, else false
arrlist.clear()removes all elements in arrlist; arrlist.size() = 0
arrlist.toString()returns string of arrlist
arrlist.remove(index) and arrlist.remove(element)arrlist.remove(index) = removes element at index and shifts remaining elements to left.<br><br>arrlist.remove(element) = removes first occurance of element and shifts remaining elements to left,                                                 returns true if element found, false otherwise.
arrlist.get(int index)retrieves element at index pos. in arrlist.
arrlist.set(int index, new element)replaces element at index with new element and returns element that was replaced
arrlist1.equals(arrlist2)returns true if both have same size, contents and order.
what is Aggregation? This means a class contains an object of another class. is used to refer one way relationship between two objects. <br>for example =<br>Student class can have reference of Address class but vice versa does not make<br>sense.<br>An employee has a home address. But vice versa, the home address has<br>employees, doesn’t sound right.
A source-code file can contain only one public class—otherwise,<br>a compilation error occurs. T or FT
what is Composition?"if one class owns another class (object of other class instantiated within this class) , and also does not share refernece of its object with other classes, and also has a striclty dependant lifetime (destroying 1 destroys the other), then we have composition.<br><br><span style=""background-color: rgb(0, 85, 0);"">For example a class Car cannot exist without Engine, as it won't be functional<br>anymore, and A bank account cannot exist without an account holder.</span>"
what is inheritance? A new class is created by acquiring an existing class’s members and possibly embellishing them with new or modified capabilities.<br>
Advantages of Inheritance"- Reduces code duplication by promoting code reuse.
- Provides a way to establish a relationship between classes, such as a parent-child relationship."
Subclass and Superclass- A subclass is more specific than its superclass and represents a more specialized group of objects.<br>- A subclass can be a superclass of future subclasses.
Subclass Modifications"- It can inherit the members of an existing class.
- It can add its own variables and methods.
<br>- It can change the meaning of inherited methods that are specific to the subclass."
private keywordA private field or method is accessible only to the class in which it<br>is defined.
protectedA protected field or method is accessible to the class itself and its<br>subclasses,
publicA public field or method is accessible to any class of any parentage<br>in any package
Private Members in Inheritance?<br>What happens to a superclass's private members in its subclasses?"- A superclass's private members are hidden from its subclasses.
<br>- They can only be accessed through public or protected methods inherited from the superclass. (getter mthods- public getVar())"
"Accessing SuperClass Members in <span style=""background-color: rgb(0, 85, 0);"">SubClasses,</span>  (public, protected and private)""- Subclass methods can refer to public and protected members inherited from the superclass directly using their names.
<br>- Private members are not directly accessible in subclasses. need getters.<br>"
Overriding Methodsto override a superclass method, a subclass must declare a methodwith the same signature as the superclass method.
Overridden method from the superclass"When a subclass method overrides an inherited superclass method, it can still access the superclass version of the method.<br><br> - To access the superclass method from the subclass, use the keyword <span style=""background-color: rgb(170, 0, 0);"">'super'</span> <span style=""background-color: rgb(170, 0, 0);"">followed by a dot (.) separator before the method name. = super.methodName()</span>"
implementation of equals method:"Implementation<br><br>Steps:<br>1. Override the `equals` method in the class, ensuring it has the signature `public boolean equals(Object obj)`.<br>2. Check if the parameter `obj` is not null and is an instance of the same class using the `instanceof` operator.<br>3. Cast the parameter `obj` to the class type to access its specific attributes.<br>4. Compare specific attributes (e.g., radii for a `Sphere` class) of the current object (`this`) and the casted parameter object to determine equality.<br>5. Return `true` if all attributes considered for equality are equal, otherwise return `false`.<br><br><img src=""paste-10c3a23b1d24755288ed1492afb5d5d32a00acf0.jpg""><br>"
"Question:
What happens when a superclass variable contains a reference to a subclass object and is used to call a method? <br><span style=""background-color: rgb(170, 0, 0);"">Thought:</span>
Consider the scenario where a superclass variable points to a subclass object. What method will be invoked when calling a method through this variable? "Answer: The subclass version of the method is called.
"Question:
What happens when invoking a method through a superclass reference in Java?
Thought:
In a scenario where methods are overridden in subclasses, what method gets executed when invoking a method using a superclass reference? "Answer: The subclass's overridden method gets executed based on the object's type, not on the type of the variable.
"Question:
How does Java handle compile-time errors related to superclass and subclass methods?
Thought:
Consider a case where a superclass reference tries to invoke a subclass-only method directly. What kind of error does Java encounter during compilation?" Answer: Attempting to invoke a subclass-only method directly on a superclass reference results in a compilation error.
"This is an example of Aggregation or Inheritance: <br><img src=""paste-2f2ab5eb8cb80a455c51062e65b408a897775527.jpg"">"aggregation
"is this an example of aggregation or inheritance?<br><img src=""paste-c5a786577d58c4260b9c2e39cf4bf01b858ed590.jpg"">"inheritance
Why can't a superclass object be treated as a subclass object?a superclass object is NOT an object of any of its subclasses, A superclass object can't be treated as a subclass object because they're fundamentally different. It's like trying to fit a square peg into a round hole - they're just not compatible.
What's the problem with assigning a superclass reference to a subclass variable?Assigning a superclass reference to a subclass variable isn't allowed because the subclass might have additional members that the superclass doesn't have. It's like trying to use a wrench when you need a screwdriver - it's just not the right tool for the job.
Field Access in Static Binding"- Access to fields in static binding depends on the type of the reference.
<br>- If a field has the same name as a field in the superclass, it hides the superclass's field."
Binding of static variables, instance variables, instance mthods + static methods?<ul><li>Static variables are bound at compile-time. <br></li><li>Instance variables are also bound at compile-time.<br></li><li>Static methods are bound at compile-time.<br></li><li>Instance methods are bound at runtime.<br></li></ul>
Casting objects in Java"You can only cast an object if the instance of the reference is a subclass of the reference;<br>Base baseInstance = new Derived(); > <span style=""background-color: rgb(170, 0, 0);"">derived extends base, reference = Base(), instance = Derived()</span><br>Derived derivedInstance = (Derived) baseInstance; <span style=""background-color: rgb(170, 0, 0);"">can cast as Instance of baseInstance is a sublcass of reference=Base()</span>"
What are concrete classes?Classes that can be used to instantiate objects are called<br>concrete classes.<br><br>Such classes provide implementations of every method they<br>declare (some of the implementations can be inherited).
What role do abstract classes play in inheritance hierarchies?Abstract classes are used as superclasses in inheritance hierarchies.
Can abstract classes be used to instantiate objects? Why or why not?No, abstract classes cannot be used to instantiate objects. They are incomplete and specify only what is common among subclasses.
What must subclasses do in relation to abstract classes to become concrete classes?"Subclasses must declare the ""missing pieces""(implement the abstact methods) specified by abstract classes to become concrete classes. Otherwise, these subclasses will also be abstract."
Is it necessary for an abstract class to contain abstract methods? Why or why not?No, an abstract class is not required to have an abstract method in it.
What is the requirement for a class that contains abstract methods?A class that contains abstract methods must be an abstract class, even if it contains some concrete (non-abstract) methods.
"What is required when a class inherits from an abstract class?<br><span style=""background-color: rgb(170, 0, 0);"">What happens if a subclass fails to implement an abstract method defined by its superclass?</span>""When a class inherits from an abstract class, it must implement every abstract member defined by the abstract class.<br><br><span style=""background-color: rgb(170, 0, 0);"">Failure to implement a superclass’s abstract method in a subclass is a compilation error unless the subclass is also declared abstract.</span>"
Can constructors and static methods be declared abstract?No, constructors and static methods cannot be declared abstract.
Can an abstract class be instantiated? If not, what can be done with references to an abstract class?An abstract class cannot be instantiated; however, references to an abstract class can be declared. These can hold references to objects of any concrete class derived from those abstract superclasses.
What happens when you have a reference of the base class type pointing to an object of the subclass type, and you attempt to call a method that is unique to the subclass(i.e., not present in the base class).You will get a compilation error. The compiler only knows about the members (methods and fields) of the reference type, and if the method you're trying to call isn't present in that type, it will raise an error.
Compile-time vs Run-time<strong>Compile time</strong> is when you build your code, and the compiler converts your source code into machine code, catching syntax and some logic errors before execution. <br><strong><br>Runtime</strong> is when your code is executed, performing its tasks and potentially encountering errors like dividing by zero or missing files
What is static binding?<ul><li>binding which happens at compile time by compiler</li><li>aka Early binding </li><li>happens b4 a program runs   </li></ul>for example: Method overloading<br>
What is Dynamic binding?<ul><li>when the compiler is cannot resolve binding at complie time</li><li>aka Late binding</li><li>happens during runtime of program</li></ul>for example: method overriding
What is binding?In Java, <strong>binding</strong> refers to the process of linking a method call to the method's actual code that will be executed. 
Static vs Dynamic binding<ul><li>Static binding uses type info for binding while dynamic binding uses objs to resolve binding not the type of reference variable.</li><li>binding of all static, private, and final methods is done at compile time.</li></ul>
What are interfaces and why do we need them?"<ul><li>an interface is something like a class which <span style=""background-color: rgb(0, 85, 0);"">ONLY</span> contains abstract <span style=""background-color: rgb(0, 85, 0);"">(minus the abstract keyword)</span> method declerations (no concrete methods/ variables)</li><li>an interface allows for multiple classes which have nothing to do with each other to inherit/<span style=""background-color: rgb(0, 85, 0);"">implement</span> common methods.</li></ul>"
Interfaces properties:"<ul><li>all interface members (methods, variables etc) must be public</li><li>interfaces must not contain <span style=""background-color: rgb(0, 85, 0);"">ANY</span> concrete methods + instance variable declerations</li><li>All methods declared in an interface are implicity ""public abstract"", which means that all the methods in the interface are abstract so no need to include the the ""abstract"" keyword as java considers these methods abstract.</li><li>All fields are public, static and final, <span style=""background-color: rgb(0, 85, 0);"">as NO instance vars allowed</span></li></ul>"
How to implement interface(s) ? syntax + what happens if the class which inherits/implements an interface does not declare all the methods?"<ol><li>to use an interface: a class must declare that it implements that specific interface e.g = public class Basketball implements <span style=""background-color: rgb(0, 85, 0);"">Bounceable, </span>to 1 or more implement interfaces --> class Basketball implements <span style=""background-color: rgb(0, 85, 0);"">Bounceable, BounceablePlus, .. etc {</span></li><li>A class which does not implement all the methods of the interface must be declared abstract.</li></ol>"
"A class can implement multiple interfaces? Y or N
"
What is the relationship between a class which implements an interface and the interface?the class has an is-a/inheritance relationship w/ interface type
Abstract classes vs Interfaces."<img src=""paste-3cc88bda0e1488f9e00b636ca0afb0f5ddb9e58c.jpg"">"
Extending interfaces? why do we do it? + syntax"<ol><li>We must extend an interface if we are to add more methods, as any classes which use this interface must now also implement the new added methods to function.</li><li>by extending the interface we can ensure that classes who would like to use this new method/functionality can now implement the new interface and those who do not can opt for the older one.</li></ol><div>the Syntax for extending interfaces: <span style=""background-color: rgb(0, 85, 0);"">public Interface newInterface  extends oldInterface</span></div>"
access of members between outer and inner classes:The outer class has access to all the members(vars, fields methods, etc) of the inner class and vice-versa
Why are nested classes used?nesting classes ia way to group classes that are only used in one place. 
Creating objects of a static nested(inner class) : from both other classes + within the outer class"<ul><li>From other classes"" Outer.staticInner name = new Outer.staticInner();</li><li>From Outer class: staticInner name = new staticInner();</li></ul>"
"Can Static inner nested classes access instance variables <span style=""background-color: rgb(0, 85, 0);"">(non static members)</span> in the enclosing/outer class? Y or N
"
"What are the 3 different types of non static inner classes:
"
"What are member classes(inner class) ? + their properties?
"
Does an instance of an outer class obj also contain the obj of the inner class? Y or NY
creating objs of inner member class: from other classes + within outer classfrom other classes:<br><ul><li>first we create an obj of outer class: OuterClass obj = new OuterClass();</li><li>next we create inner obj: OuterClass.InnerClass inner = obj .new InnerClass();</li></ul>within outer class:<br><ul><li>InnerClass obj = new InnerClass();<br></li></ul>
What are Local Classes (inner class), Why are they used + their properties?What are local classes + Why are they used:<br><ul><li>class which is defined within a method of the outer class.</li><li>Used when a class is only needed inside a method to do a special task which is not helpful to the rest of our program.</li></ul>Local classes Properties:<br><ul><li>Cannot be declared with an access modifier(public, protec. priv. ) follows the default syntax = class LocalClass {...} </li><li>must not include static (vars + methods).</li><li>local classes can access the fields of their Outer class + local variables of the method they are declared in.</li></ul>
How can we access a Local class?<ul><li>A Local class can only be accessed via the method which encapsulates it within the outer class.</li><li>this is done by calling the method the method within the outer class on a Outer class obj/instance.</li></ul>
What are Anonymous classes ? Anonymous classes in Java are a type of Local class that do not have a name and are declared and instantiated at the same time. They are typically used when you need to create a class that implements an interface or extends a class, but you don't need to reuse the class elsewhere in your code. Anonymous classes are useful for creating quick, one-time use instances of classes.
 what must happen after u define/declare a Local inner class?"U must instantiate the class e.g : <br><img src=""paste-74dc8bed777c70134bcdb0df7d05a6effd82e943.jpg"">"
"Creating an anonymous class:<br>The syntax is as follows:<br><img src=""paste-9dd03421bd6fe617f3ab75ae2691ddb8892e985c.jpg"" width=""615""><br>"<ol><li>Supertype can be an interface that the anon. class implements OR it can be a class that the anonymous class extends.</li><li>class body defines methods but no constructors allowed.</li></ol>
Anonymous classes properties?"<ul><li><span style=""background-color: rgb(0, 85, 0);"">Anonymous inner classes have no name.</span> therefore You can't execute the instanceof test or any process that requires the name of the class.<br></li><li>Anonymous inner classes can't implement multiple interfaces.</li></ul>"
what is the iterator interface do?"is a ""one-shot"" obj , which goes thru all the elements of a ""Collection at once."""
Steps to implement an iterator obj:"<ol><li>outer class implements Iterable<E> interface. <span style=""background-color: rgb(0, 85, 0);"">class Outer implements Iterable<E></span></li><li>next we define iterator method to return new instance of iterator class(inner class). <span style=""background-color: rgb(0, 85, 0);"">public Iterator<E> iterator() { return new OuterIterator;}</span></li><li>next we define inner class which implements interface Iterator<E> and declares the methods hasNext() --> boolean <span style=""background-color: rgb(0, 85, 0);"">returns true if there exists more elements in collection</span>, and <span style=""background-color: rgb(0, 85, 0);"">next() --> usually returns new E(valAtNextIndex++)</span> .</li></ol>"
How do i know if exception handling should go inside or outside a loop?<div>It depends on how you want to handle the exception. If you want to continue the loop even if an exception occurs during one iteration, then the exception handler should be inside the loop. If you want to abort the loop, then the exception handler should be outside of the loop.</div><div>For example, if you enter an improper input, it may produce an exception (for example, you could end up doing a division by zero). If you want to print an error message and terminate the application, it would make more sense to put the exception handling outside of the loop.</div><div>If you put exception handling inside the loop, then the loop can continue to run even after an error has occurred.</div>
What is a JFrame?"<ul><li><span style=""background-color: rgb(0, 85, 0);""><strong>Base of the GUI</strong></span>: A <code>JFrame</code> is essentially the base window of a Swing application. It provides a container for other GUI components like buttons, labels, text fields, and panels.</li><li><span style=""background-color: rgb(0, 85, 0);""><strong>Window</strong>:</span> It represents a standard window that has decorations such as a title, a border, and buttons for closing, minimizing, and maximizing the window.</li><li><span style=""background-color: rgb(0, 85, 0);""><strong>Main Application Window</strong>:</span> In a typical Swing application, a <code>JFrame</code> serves as the primary window where other components are added and arranged.</li></ul>"
What is a JPanel?A panel is a container that is used to group components(such as buttons + text fields), and can in turn be added to another container e.g. a JFrame instance.
How to add components to a Jpanel instance?"<ol><li>create new JPanel instance : <span style=""background-color: rgb(0, 85, 0);"">JPanel p = new JPanel();</span></li><li>use the add() method on panel instance to add specified component e.g  <span style=""background-color: rgb(0, 85, 0);"">p.add(new JButton(""OK""));</span></li></ol><br>"
what are JTextFields, JButtons and JLabels"<ul><li><div><span style=""background-color: rgb(0, 85, 0);""><strong>JTextField</strong>:</span> This is a text box in a program where you can enter and edit text. Think of it like the input fields you see on a website where you type your username or search queries.</div></li><li><div><span style=""background-color: rgb(0, 85, 0);""><strong>JButton</strong>:</span> This is a clickable button in a program. When you click it, it performs an action, like submitting a form or starting a new game. It's like the buttons you click on websites to log in or register.</div></li><li><div><span style=""background-color: rgb(0, 85, 0);""><strong>JLabel</strong>:</span> This is a simple component that displays a line of text or an image in a program. It's like a label on a form or a caption under a picture that provides information or instructions.</div></li></ul>"
How does event handling work?<ul><li><strong>Event Source</strong>: The component that the user interacts with, which triggers events (e.g., a button).</li><li><strong>Event</strong>: The user interaction itself (e.g., clicking the button).</li><li><strong>Event Listener</strong>: Defines the reaction to the event (e.g., what happens when the button is clicked).</li></ul>
Implementing event Handlers/Listeners?"<ol><li>Create a class that represents the event handler.<br>class--> <span style=""background-color: rgb(0, 85, 0);"">MyListener implements ActionListener {</span><br></li><li>implement an event-listener interface in yout event handler class (MyListener)--> <span style=""background-color: rgb(0, 85, 0);"">public void actionPerformed(ActionEvent e) {...}</span> </li><li>create an instance of that handler in the Outer class/ GUI class.--> <span style=""background-color: rgb(0, 85, 0);"">MyListener handler = new MyListener();</span></li><li><span style=""white-space: pre;"">Register the listener with the GUI component(s). This is known as<br>registering the event handler. <span style=""background-color: rgb(0, 85, 0);"">textField1.addActionListener( handler );</span><br></span><span style=""background-color: rgb(0, 85, 0);"">textField2.addActionListener( handler );  </span></li><li>multiple components may register the same handler if the same action must be performed on both.</li></ol>"
new JButton(str) creates a new button with the specified text inside (str)
Jlabel(str)Creates new label with given string as its text.
component.getText()returns the str on the component.
Component.setText(String text)sets the str specified on the component
JTextField(int columns)specifies how many columns longs the input text field is.
JTextArea(int lines, int columns)specifies how many rows/colums wide the text box is.
Event handling with anonymous classes?"<ol><li><div><strong>Add a new <code>ActionListener</code> object to the component</strong>:</div><ul><li>Use the <code>addActionListener</code> method of the component (e.g., <code>JButton</code>).</li></ul></li><li><div><strong>Indent the next couple of lines of code and implement the <code>actionPerformed</code> method</strong>:</div></li><ul><li>Inside the <code>actionPerformed</code> method, define the actions that should happen in response to the event.</li></ul></ol><span style=""background-color: rgb(0, 85, 0);"">textField1.addActionListener( new ActionListener() {<br>    public void actionPerformed( ActionEvent e ) {...}<br>}</span><br>"
ArithmeticExceptionattempt to divide by ZERO
ArrayIndexOutOfBoundExceptionuse of an invalid array index
NullPointerExceptionan attempt to use an object reference that hasn’t yet<br>been assigned to an object
basic syntax of try, catch block:try : place code that might cause exception in try block<br>catch: specifiy exception u wish to catch.
What order should catch clauses be in?if you have more specific catch clauses place them before the general excpetion (exception e)
finally block in excpetions.Code within a finally block is guaranteed to be executed if<br>any part of the associated try block is executed regardless of an<br>exception being thrown or not
throwing exceptionsif (condition){<br>    throw new Exception(“Exception occurs.”);<br>}
Which one should I use? try and catch or throws<ul><li>Use try and catch --> If it’s clear what action should be taken and if the local block can perform that action.<br></li><li>Use throws --> Where it’s not clear what action should be taken.<br></li></ul>
"what are these class relationships?<br><img src=""paste-12c0da7191498e9a1d083c471168d16696a1d272.jpg"">""<img src=""paste-14c6446b9293a41f38c74b9dff90118c4703c677.jpg"">"
What is a dependency relationship?If the variable scope is method level (limited to a few methods) such as a constructor, and class does not contain a reference of this object , then we call this association dependancy or weak association.<br>
What is method level scope?<strong>Method-level scope</strong> refers to local variables that are declared within a method. These variables are only accessible within the method where they are defined and are created when the method is called and destroyed when the method exits.
What is an simple association?if the scope is object level, but this class does not own the other object, then the relationship is simple association, eg  this class does have a reference to a var of other object but no other object is created instantiated within this class. <br><br>other obj var is generally instantiated ouside of this class and passed into a this classe's constructor etc.
What is Object-Level scope?<strong>Object-level scope</strong> refers to instance variables (also known as member variables or fields) that are defined within a class but outside any method. These variables are associated with a particular instance of the class, meaning each object created from the class has its own copy of these variables.
"if a class' object owns another class' obj as an obj-level variable <span style=""background-color: rgb(0, 85, 0);"">( e.g class Car has var. new Engine obj) </span>what type of assocaiation is this at THE LEAST."Aggregation at THE LEAST.
"If one class owns another class, and also does not share the referance of its object with other classes, and also has a strictly dependant lifetime <span style=""background-color: rgb(0, 85, 0);"">(destroying one destroys the other)</span>, what type of association relationship is this?"Compositon association.
"What are these four associations?<br><img src=""paste-a527e08abff85cd4eb6de5c4bdebaeda572078ac.jpg"">""<img src=""paste-4114932747b3ab879e8ffe17abcdf4360db0363b.jpg"">"
Single Responsibility Principle?The Single Responsibility Principle is about ensuring that a class has only one reason to change by focusing on a single responsibility. This principle promotes better design, leading to more maintainable, testable, and understandable code. By adhering to SRP, developers can create systems that are easier to manage and extend over time.
What is the Open-Closed Principle?The Open/Closed Principle emphasizes that software entities should be designed in a way that allows their behavior to be extended without modifying their source code. This is typically achieved through the use of interfaces, abstract classes, and inheritance. Adhering to OCP makes the codebase more maintainable, flexible, and scalable, facilitating easier addition of new functionalities with minimal risk of introducing bugs into existing code
The Liskov Substitution Principle?The Liskov Substitution Principle ensures that subclasses can stand in for their base classes without altering the expected behavior of the program such that if you substitute one class for the other (super + subclass) it does not alter the correctness of the program. that derived classes extend the functionality of their base classes without changing their core behavior.
The Interface Segregation Principle? e.g Printer example."The Interface Segregation Principle encourages the use of multiple, client-specific interfaces instead of one large, general-purpose interface. e.g if an Interface printer has 3 methods print(), fax(), scan() but the client only desires the print functionality, the ISP states that rather than implement the unneccessary methods, we can use multiple smaller ""client specific interfaces"" such that only the neccessary functionailties are implemented."
The Dependency Inversion Principle?The Dependency Inversion Principle promotes the decoupling of high-level and low-level modules by making both depend on abstractions (abstract classes/interfaces)  rather than concrete implementations (classes).
What do these Association Multiplicities mean?<br><ul><li>*</li><li>1</li><li>0..*</li><li>1..*</li><li>0..1</li><li>2..4 --> a..b</li></ul>"<ul><li>Many</li><li>Exactly 1</li><li>Zero or More</li><li>One or More</li><li>Zero or One</li><li>Specified range (can contain <span style=""background-color: rgb(0, 85, 0);"">min a</span> and <span style=""background-color: rgb(0, 85, 0);"">max b)</span></li></ul>"
"Explain this multiplicity:<br><img src=""paste-f543e5bc117d48f3013984122c774662996fb256.jpg"">"Borrower can have upto 5 books, min 0 -- max 5<br>and A single book can have upto 1 borrower, min 0 -- max 1
Composite Design Pattern:This pattern lets you build a tree structure of objects where you can treat both individual objects and groups of objects the same way. It helps you work with complex object hierarchies more easily by allowing you to use simple and complex objects interchangeably.
What is the template method pattern?"This pattern defines the basic structure of an algorithm in a method of a superclass.Template Method allows subclasses to redefine certain steps of an algorithm without changing the algorithm’s structure.<br><br>""The algorithm defined in the superclass method includes steps that can be overridden by subclasses to implement varying behaviors (does slightly different things for each subclass) for the same overall algorithm."""
What is the Observer Pattern?Design pattern that defines a one-to-many relationship between objects so that when one object (the subject-observable) changes its state, all its dependents (observers) are notified and updated automatically.
implementing a template method pattern:<ul><li>Give hook methods protected access  --> They’re not intended to be called by clients</li><li>Define mandatory hook (slot) methods as abstract in the superclass. --> steps subclasses MUST implement</li><li>Implement optional hook (also known as primitive) methods in the superclass. --> have a default behaviour but CAN be overridden by sublasses</li><li>Define template methods as final. --> Subclasses shouldn’t make arbitrary changes to the behaviour of a template method.</li></ul>
"explain the following class diagram (observer-pattern) think of a clock and people observing the clock:<br><img src=""paste-f374aaaae83e831082c36985496444d9e7c76cce.jpg"">"<ul><li>Clock implements observable interface + methods (addObserver() and notifyObserver())</li><li>Observer = ClockViewer implements observer interface +  update() method.</li><li>everytime the clock updates --> time changes we notify the observers so they can see this update in real-time, assuming we have already added observers.</li><li>the update(Observable obs, Object obj) method defines actions that can be taken by obsservers after recieving update notification in the observable.</li></ul>
What is the Adapter pattern?also known as the Wrapper Pattern, is a design pattern in software engineering that allows incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces, enabling them to communicate and interact with each other. The Adapter Pattern is part of the Structural design patterns and is widely used to make existing classes work with others without modifying their source code.
How to implement the Adapter Pattern?"Identify the <span style=""background-color: rgb(0, 85, 0);"">Target interface</span> which the client wants to work with (this interface includes the methods + functionalities specific to the clients needs.<br><br>We currently have an existing class known as the <span style=""background-color: rgb(0, 85, 0);"">Adaptee</span> which has the desired functionality but has an incompatible interface.<ul><li>Incompatible interface means that methods between the adaptee and interface do not match.</li></ul>Thus we create a helper class (<span style=""background-color: rgb(0, 85, 0);"">Adapter</span>) that implements the desired/target interface.  <br><ul><li>The Adapter class contains an instance of the Adaptee class.</li><li>The Adapter now overides/implements the methods in the target interface using the methods from the Adaptee (via adaptee instance) to complete the functionality.</li></ul><div>we then intergrate the Adapter whith the client class.</div>"
Model View Controller(MVC). Define what Model, VIew and Controller do.Model (back-end):<br><ul><li><b>What it is:</b> The Model represents the data and the business logic of the application. aka the state.</li><li><b>What it does: </b>It directly manages the data, logic, and rules of the application. It can respond to requests for info/state changes, usually from the View, and it can respond to instructions to change state, usually from the Controller.</li></ul><div>View (front-end):</div><div><ul><li></li><li><strong>What it is</strong>: The View represents the user interface.</li><li><strong>What it does</strong>: It displays the data from the Model to the user and sends user actions to the Controller. It’s the visual representation of the model. The view can be any output representation of data, such as a chart, diagram, or table.</li></ul>Controller:</div><div><ul><li><strong>What it is</strong>: The Controller acts as an intermediary between the Model and the View.<br></li><li><strong>What it does</strong>: It takes the user input from the View, processes it (possibly modifying the data in the Model), and returns the display output to the View. It interprets the user inputs, informing the Model and/or the View to change as appropriate.<br></li></ul></div>
How MVC Works<ul><li>The user interacts with the View (e.g., clicking a button).</li><li>The Controller receives the input from the View. It processes the input, potentially changing the state of the Model.</li><li>The Model updates its state based on the Controller's action (e.g., fetching new data, updating existing data).</li><li>The View queries the Model to get the latest data and updates the display for the user.</li></ul>
What is a TreeModel?it its a data model for a JTree
2 ways to create a tree model? <ul><li>via inbuilt DefaultTreeModel class in java</li><li>create a new class which implements the TreeModel interface + its methods.</li></ul>
Creating JTree using DefaultTreeModel"<ol><li>create JTree obj reference  and DefaultTreeModel obj --> <span style=""background-color: rgb(0, 85, 0);"">JTree tree; DefaultTreeModel dtm;</span></li><li>Add a root node --> which will always be the first node u add.  <span style=""background-color: rgb(0, 85, 0);"">DefaultMutableTreeNode root = new DefaultMutableTreeNode(""-root name here-"");</span></li><li>Add as many other nodes using the same approach as above, however u need to invoke the method root.add(childNode) to add the node to parent.</li><li>finally to construct the JTree --> we need to create the DefaultTreeModel instance with the above reference we created --> <span style=""background-color: rgb(0, 85, 0);"">dtm = new DefaultTreeModel(root);</span> and add the DefaultTreeModel instance to a JTree instance with the above reference we created --> <span style=""background-color: rgb(0, 85, 0);"">tree = new JTree(dtm);</span></li></ol>"
Using the DefaultTreeModel to do actions when selecting a node in JTree?<br>e.g returning node <br><br><div><ul><li><div><strong>Implement an inner class which implements the <code>TreeSelectionListener</code> interface</strong>: This is a common approach. Inner classes can be convenient for encapsulating event-handling logic.</div></li><li><div><strong>Implement the <code>valueChanged(TreeSelectionEvent e)</code> method</strong>: This is the method where you'll put the logic to handle the tree selection event. It will be called whenever the selection in the tree changes.</div></li><li>obtain last selected node by calling getLastSelectedPathComponent() --> if this node != the root or null then get node object by calling the getUserObject() method.</li><li>getUserObject() returns variable of superclass Object type therefore u must cast the reference b4 using the method --> e.g Country c = (Country) node.getUserObject()<br></li></ul></div><br>
what does collapseRow(int row) do in a JTree?This method collapses the specified row in the tree, hiding its child nodes. If the row is already collapsed or if it doesn't have any children, this method has no effect. When you collapse a row, its children are no longer visible in the tree.<br><br>e.g tree.collapseRow(3); // Collapses the row at index 3
what does expandRow(int row) method do in a JTree?This method expands the specified row in the tree, revealing its child nodes. If the row is already expanded or if it doesn't have any children, this method has no effect. When you expand a row, its children become visible in the tree.<br><br>tree.expandRow(2); // Expands the row at index 2
what does the setSelectionRow(int row) method do in a JTree?This method selects the specified row in the tree. If the row is not visible in the tree, it will be expanded to make it visible. This method is typically used to programmatically select a row in the tree.<br><br>tree.setSelectionRow(4); // Selects the row at index 4
Using the DefaultTreeModel to add a new Node?<ol><li>create inner class which implements the ActionListener interface and the actionPerformed(ActionEvent e) method</li><li>get the new node name from JTextField --> JTextField.getText()</li><li>creates a new node obj from acquired text --> DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(-acquired text-)</li><li>get the number of children of the JTree by calling getChildCount(root)</li><li>invoke the insertNodeInto() method --> insertNodeInto(newNode, root, index)</li><li>the index is acquired from getChildCount. </li></ol>
Using the DefaultTreeModel to remove a node from a JTree?<ul><li>define an inner class which implements the ActionListener interface and actionPerformed(ActionEvent e) method</li><li>we get the last selcected node by using the getLastSelectedPathComponent() method</li><li>if the last selected node != the root or is not null invoke the removeNodeFromParent(node) method to remove selected node.</li></ul>
Using the TreeModel interface?"<ul><li>create a class named XXXTreeModel <span style=""background-color: rgb(0, 85, 0);"">(XXX -> repr a class with a composite structure e.g nodes which have children (subtrees))</span> which implements the TreeModel interface.</li><li>define the following:  root + tree model listeners</li><li>implement methods getRoot(), getChild(), getChildCount(), getIndexOfChild() and isLeaf()</li></ul>"
using the TreeModel interface to insert nodes to a Composite/Parent node."<ul><li>Complete the insertNodeInto(Leaf newChild, Composite Parent, int index) --> if the parent is a composite add the newChild to the parent node</li><li>invoke the fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)</li><li>where the sources = the source of the TreeModelEvent, typically <span style=""background-color: rgb(0, 85, 0);"">this</span>.</li><li>path = path from root to parent e.g [root, child]</li><li>childIndices int array = contains indices of added children/nodes. [0, 1,..]<br></li><li>children obj array =  added children/nodes = [child1, child2, .. etc]</li></ul>"
using the TreeModel interface to delete nodes from a Parent node.<ul><li>Complete the removeNodeFromParent(XXX selectedNode), XXX is the superclass of the composite subtree (node containing leafs) class.</li><li>get the Parent of the selected node</li><li>get the index of the selected node in the parent node</li><li>remove the object/node from parent node.</li><li>invoke fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) method</li></ul><div><ul><li>where the sources = the source of the TreeModelEvent, typically this.</li><li>path = path from root to parent e.g [root, child] node is removed from this.</li><li>childIndices int array = contains indices of removed children/nodes. [ 1,..]<br></li><li>children obj array =  removed children/nodes = [child1, child2, .. etc]</li></ul></div>
Creating a List Model using DefaultListModel class?"<ol><li>create a JList reference and DefaultListModel<E> obj --> JList<String> list; and DefaultListModel<String> dlm = new DefaultListModel<String>();</li><li>add items to the the List model using ListModel.addElement(E) --> dlm.addElement(""banana""); etc</li><li>after appending desired element/items to listModel create new JList using the DefaultListModel instance --> list = new JList<String>(dlm);</li></ol>"
JList EventHandling -> Selecting an element:<ol><li>Define an innerclass which implements the LIstSelectionListener interface. </li><li>Define the valueChanged(ListSelectionEvent e) method()<br></li><li>within the valueChanged() method if the ListSelectionEvent e is not adjusting (!e.getValueIsAdjusting()) then we retrieve the selected value by calling getSelectedValue() on JList instance.</li></ol>
JList EventHandling -> Adding a new element:<ol><li>Define an innerclass which implements the ActionListener interface. </li><li>Define the actionPerformed(ActionEvent e) method</li><li>get info/text from JTextField.getText()</li><li>invoke the addElement(newElement) method to insert a new element</li></ol>
JList EventHandling -> Removing Selected element:<ol><li>Define an innerclass which implements the ActionListener interface. </li><li>Define the actionPerformed(ActionEvent e) method</li><li>get selected index by calling JList.getSelectedIndex() method</li><li>invoke the removeElementAt(int index) to remove element at the selected index.</li></ol>
Creating a List Model using AbstractListModel class?"<li>Define Class: <code>XXXListModel<XXX></code> extends <code>AbstractListModel<XXX></code>. XXX is the object type.</li><li>Basic Methods:<ul><li><code>getSize()</code>: Returns list size.</li><li><code>getElementAt(int index)</code>: Returns element at index.</li></ul></li><li>Add Elements:<ul><li>Add element to list by implementing addElement(element).</li><li>Call <code>fireIntervalAdded(this, index, index)</code>. to notify observers.</li></ul></li><li>Remove Elements:<ul><li>Remove element from list by calling removeElementAt(int index).</li><li>Call <code>fireIntervalRemoved(this, index, index)</code></li><li><font face=""monospace"">finally create XXXlistModel class instance, add elements + use instance to create JList -> Jlist list = new JList<XXX>(XXXlm instance);</font></li></ul></li>"
"General Concept of ""Fire"" Methods in Swing Frameworks ?, for example what does  fireIntervalRemoved(Object source, int index0, int index1) do?""""Fire"" methods in Swing frameworks notify registered listeners about changes in a data model. They ensure that the graphical representation of the data stays synchronized with its actual state, ensuring an accurate user interface.<br><br>e.g fireIntervalRemoved(Object source, int index0, int index1) --> Notifies listeners that elements have been removed from the data model within the specified interval."
What are JTables?Tables used to display data in a spreadsheet format.<br>
Using a DefaultTableModel:"<ol><li>create 2d array with predetermined values Object[][] <span style=""background-color: rgb(0, 85, 0);"">data</span> = {{row1},{row2}}, number of items in a row = no. of columns. <span style=""background-color: rgb(0, 85, 0);"">row1 = values = {1, 2, 3,..etc}</span></li><li>create an String array which establishs column headers, String[] <span style=""background-color: rgb(0, 85, 0);"">colNames</span> = {col1, col2,..,etc}</li><li>use these instances to create a DefaultTableModel object instance DefaultTableModel dtm = new DefaultTableModel(<span style=""background-color: rgb(0, 85, 0);"">data, colNames</span>)</li><li>now use the DefaultTableModel instance to create a JTable  --> table = new JTable(dtm);</li></ol>"
tableModel.setValueAt(value, row index, column index)<br>takes a value and column and row indices, replaces current value in table at col + row index to specified value.
tableModel.insertRow(rowIndex, values)adds a row to the table as specified row index, with the specified values<br>values = {rowIndex-col1, rowIndex-col2,.., etc}
tableModel.removeRow(rowIndex)removes row at rowIndex.
Using the AbstractTableModel:<ol><li>create new anonymous class which extends the AbstractTableModel class --> JTable table = new JTable(new AbstractTableModel (){...}</li><li>within the ... we override the getColumnCount(), getRowCount(), and getValueAt(int row, int col) methods.</li></ol>
setValueAt(value, rowIndex, columnIndex) in AbstractTableModel:<div><ol><li><strong>Implement <code>setValueAt(value, rowIndex, columnIndex)</code> in your <code>AbstractTableModel</code> subclass:</strong><ul><li>This method should update the value at the specified row and column indices.</li><li>After updating the value, call <code>fireTableCellUpdated(rowIndex, columnIndex)</code> to notify any observers. Without this, the change will not be visible in the table.</li></ul></li></ol></div>
isCellEditable(rowIndex, columnIndex)set this to true to allow users to update values from JTable.
Adding new Row using AbstractTableMethod:<ul><li>add new element to array.</li><li>invoke fireTableRowsInserted(row1, row2) --> if only one change row1, row2 value should be the same.</li></ul>
removing row using AbstractTableModel:<ul><li>remove element from array list.</li><li>fireTableRowsDeleted(index, index) method to reflect changes --> index values are == if only one row is removed.</li></ul>
What is the singleton design pattern."design pattern which ensures that a class has only one instance. while providing a global access point <span style=""background-color: rgb(0, 85, 0);"">(instance can be accessed from anywhere within the program)</span> to this instance"
Singleton Design Pattern implmentation.<ul><li>create constructor of class u want to implement design pattern on to private e.g private Cat(string name)</li><li>create a static creation method --> checks if instance = null, if true creates a new Singleton type class obj. + returns instance. </li></ul>
What is the factory method?A factory method is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created
What is Multi-Processing?divinding instructions of task given to the CPU into multiple segments such that each segment is assigned a seperate thread to execute the said task.
What is a Thread?thread is the smallest unit of a process, each process/ instruction has multiple threads such that each thread is individual to each other.
What is the advantage of Threads?when the CPU is assigned a instruction and it is split amongst threads, since Threads are independent of one another, if a single Thread were to break/malfunction the process will not be affected and process is still carried out.
New stage of Thread-Life cycle:new thread created using Thread class 
runnable stage in Thread-Life cycle:after Thread creation, Thread is assigned to a process and is ready to be executed/run.
Running stage of Thread Life-Cycle:Os/process scheduler begins execution of process using the thread. continues until finished.
Dead stage of Thread Life-Cycle:termination of Thread and thread is killed after process finished.
Waiting state in thread-Life-Cycle:A thread may place itself in a Waiting state when waiting for another thread to perform a task.<br>It will remain this way until it is notified by another thread.
Blocked state in Thread Life-Cycle:A thread in the Runnable state will switch to Blocked when it attempts to perform a task that<br>it can’t perform immediately. It must wait until the other task blocking it completes before it returns to Runnable
using thread class:"<ol><li>create custom Threadclass -> myThread which extends Thread.</li><li>override the run method </li><li>in test class <span style=""background-color: rgb(0, 85, 0);"">(public static void main(String[] args))</span> create myThread instance and use Thread.start(); to start process.</li></ol>"
using Runnable interface:"<ul><li>Define a new class that implements the Runnable interface</li><li>Implement the run() method of the Runnable interface</li><li>Within the run() method we place our code to be executed by the thread. i.e. our ‘Task’</li><li>Instantiate a Thread with our custom runnable in the constructor, along with the thread name. <span style=""background-color: rgb(0, 85, 0);"">Thread thread1 = new Thread(myRunnable);</span></li><li>Call the start() method on the instantiated Thread.</li></ul>"
How to execute one Thread before the other when both Threads are run --> t1.start(), t2.start()"try {
<br>     t1.start();<br>     t1.join(); // Wait for t1 to finish before starting t2
<br>     t2.start();
<br>} catch (InterruptedException e) { e.printStackTrace();
}"
Using synchronized keyword on a method?"allows only one thread at a time to execute this method, Any other threads attempting to access this method will be placed into the blocked state."
When to use synchronized keyword?whenever you have multiple threads working on shared data or resources, it is crucial to synchronize access to those resources to prevent race conditions and ensure data consistency --> e.g make run method synchronized.
calling sleep() method to synchronize method/run():"<ul><li>invoking sleep(…) on a thread takes it to the time waiting state </li><li>After the sleep time allocated to the relevant thread expires, the thread is brought back to the runnable state (Ready queue) </li><li>sleep(…) calls can be used to synchronize threads.</li></ul>"
e.printStackTrace()When called on an instance of <code>Throwable</code> (such as an exception object), <code>printStackTrace()</code> prints the entire stack trace starting from the point where the exception was thrown up to the point where it was caught (if it was caught).
swing worker methods --> publish(), get(), execute():"are template methods, holding the ""common"" code.<br>"
SwingWorker methods --> doInBackground(), process(), and<br>done()?"The overridable methods doInBackground(), process(), and done() serve as hook methods, in which client code provides the (variable) details for the various ""steps""."
<strong>Compile-time Binding vs </strong><strong>Runtime Binding? in terms of member accesss.</strong><li><strong>Compile-time Binding</strong>: Determines access based on the reference type (class).<ul><li>Applies to static variables, instance variables, and static methods.</li></ul></li><li><strong>Runtime Binding</strong>: Determines access based on the actual object(instance) type.<ul><li>Applies to instance methods (polymorphic behavior).</li></ul></li>
Must-Dos for Implementing the Singleton Pattern:"<ul><li><div style=""display: inline !important;""><span style=""background-color: rgb(0, 85, 0);""><strong>Private Constructor</strong>: </span></div>The constructor should be private to prevent the instantiation of the class from outside the class.</li><li><div><span style=""background-color: rgb(0, 85, 0);""><strong>Static Instance</strong>:</span> A static member variable should hold the single instance of the class. This instance should be initialized lazily or eagerly based on the specific Singleton implementation.</div></li><li><div><span style=""background-color: rgb(0, 85, 0);""><strong>Public Static Method</strong>:</span> Provide a public static creation method that returns the instance of the class. This method ensures that the instance is created if it does not already exist and returns the existing instance if it does.</div></li></ul><div>Extras: </div><div>Prevent breaking the Singleton pattern using reflection by throwing an exception in the constructor if an instance already exists. retrieve the singleton instance if null create instance else don't.<br></div>"
Download