Docsity

Mid Term, In class notes | CS 2114 - Softw Des & Data Structures, Quizzes of Computer Science

Toggle sidebar
bg1
TERM 1
Static keyword
DEFINITION 1
this allows you to declare methods and variables as
belonging to the class instead of to an instance to the
class.meaning you can call and use them in as
below:ClassName.STATIC_VARIABLE or
instanceOfClass.STATIC_VARIABLEClassName.StaticMethod()or
instanceOfClass.StaticMethod()we have used both of these in
the minesweeper app
TERM 2
Protected
DEFINITION 2
This modifier lets the variable or method be accessed by any
instances of the class it is in, any subclass, and any other
classes within the same package.
TERM 3
Private
DEFINITION 3
This modifier allows access to the variable only by the class
it is in.
TERM 4
public
DEFINITION 4
This modifier allows access to the method through any class,
it is similar to the "Universal" variables and methods in c++.
TERM 5
Interface
DEFINITION 5
An interface is used as an "outline" for a class. This type of
class will only have empty method declarations in it, and
some variables but any variable declared will be static and
final (value cannot be manipulated). You cannot create an
instance of an Interface. A class can implement multiple
interfaces.
pf3
pf4
pf5

Partial preview of the text

Download Mid Term, In class notes | CS 2114 - Softw Des & Data Structures and more Quizzes Computer Science in PDF only on Docsity!

Static keyword

this allows you to declare methods and variables as belonging to the class instead of to an instance to the class.meaning you can call and use them in as below:ClassName.STATIC_VARIABLE or instanceOfClass.STATIC_VARIABLEClassName.StaticMethod()or instanceOfClass.StaticMethod()we have used both of these in the minesweeper app TERM 2

Protected

DEFINITION 2 This modifier lets the variable or method be accessed by any instances of the class it is in, any subclass, and any other classes within the same package. TERM 3

Private

DEFINITION 3 This modifier allows access to the variable only by the class it is in. TERM 4

public

DEFINITION 4 This modifier allows access to the method through any class, it is similar to the "Universal" variables and methods in c++. TERM 5

Interface

DEFINITION 5 An interface is used as an "outline" for a class. This type of class will only have empty method declarations in it, and some variables but any variable declared will be static and final (value cannot be manipulated). You cannot create an instance of an Interface. A class can implement multiple interfaces.

Abstract Class

An abstract class will have variable fields, some implemented methods and some abstract methods (methods that are not implemented.) Your class can extend only one Abstract Class. TERM 7

Aliasing

DEFINITION 7 This is when you have to variables pointing to the same object.Animal cat1 = new Animal();Animal cat2 = cat1;cat == cat2, this statement is true. TERM 8

this

DEFINITION 8 the keyword this lets the IDE during run-time know that you are referring to the variable defined in the class not the parameter or local variable of the method.private Animal cat;public void assignCat(Animal cat){ this.cat = cat;} TERM 9

super

DEFINITION 9 This keyword lets the IDE know during run-time that you are referring to the method or variable that belongs to the Parent class (the class that is extended) and not the locally declared variable or method. TERM 10

Polymorphism

DEFINITION 10 Polymorphism allows you to treat all subclasses of a particular class as an instance of that class. We know that String is a subclass of Object, so the following statements are allowed .Object obj = "a string";or a method declaredpublic void equals(Object obj){ if (obj instanceOf String) { obj.equals(this.obj)} } can be calledequals("a string");

Controller

this connects the model with the viewIt also handles user input on the GUI TERM 17

MVC Class design

DEFINITION 17 The model, the view and the controller can all have multiple classes.The intent is to keep the concepts decoupled. It is also best to keep your controller class simple and concise decision making etc. should be handled in the view or the model. TERM 18

Coupling

DEFINITION 18 This is a measurement of how much multiple classes rely on each other, you want loose coupling so it is easier to modify the code w/o breaking anything in the other classes. TERM 19

Cohesion

DEFINITION 19 This is how much a class relies on other classes, you want high cohesion meaning it does not rely heavily on multiple other classes. TERM 20

Arrays

DEFINITION 20 fixed size Pimitive types such as int are allowed this has a fixed layout

ArrayList

size is variable Primitives must be wrapped you can use Integer instead of int you can easily insert and remove values is generic meaning uses ArrayList when creating a new arraylist object use the format new ArrayList TERM 22

ArrayList generics

DEFINITION 22 constricts the object types allowed to be out in the ArrayList eliminates the casting when getting values from it better code documentation Can use ArrayList omitting the generics so that it is Backwards compatible for older code TERM 23

Creating an ArrayList class

DEFINITION 23 use System.arraycopy(array1, 0, array2, 0, size) for copying the array over when making a new bigger array when inserting your copying loop should start at the end of the array and move to the left copying the values to the right to move them down when removing start at the index you wish to remove and copy the next value into your current location then set the value that was at size - 1 to null when adding to the array make sure you have room. if size = contents.length then make array twice as big TERM 24

throwing an exception

DEFINITION 24 use throw new exceptionType("String you want your exception to say");So far we have just used the exception types that Java already has defined. IndexOutOfBoundsException and I believe the other one was InvalidStateException but I am not sure. We also in lab 6 used an exception that was defined in the teachers code but we have not had to create our own. TERM 25

Try, Catch

DEFINITION 25 This is for testing thrown exceptions, or handling exception when your code throws them. It is usually better practice to avoid using them for the second situation and simply use better logical operations. use the following format.Exception thrown = nulltry { your code here}catch(Exception e) { thrown = e }now assert that thrown is an instanceOf your expected exception or using thrown.getMessage() you can make sure your message matches

Linked lists

This is a structure containing a group of nodes where each node has a pointer to the next node. We have only reviewed Linked lists with unidirectional pointing, just one pointer. This class provides join which allows you to assign the pointer from one object to the next A.join(B) makes A point to B then it returns A so that statements such as A.join(B.join(C)) can make B connect to C then A connect to B. Split allows you to remove the link to the next object.