




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





this and super The difference between this and super: โ this represents the current instance of a class โ super represents the current instance of the parent class. How to use each one to call a method โ Using this.act( ) would invoke the method in the current instance of the class โ Using super.act( ) would invoke the method in the current instance of the parent class How to use each one to call one constructor from another โ You can use this( ) to call no argument constructor of same class. โ You can use super( ) to call no argument or default constructor of the parent class. โ Reference variable that is declared โfinalโ cannot ever be reassigned References What a reference variable is โ Using a reference variable, we can access an object. โ References are stored in reference variables โ Reference variables can hold Fields, parameters, or local variables โ A reference variable is declared to be of a โspecific typeโ and that type can never be changed. The object r1 = r2; โ Assignment copies the reference. It does not duplicate โ Object variables are simply pointers to objects โ Primitive variables (ints booleans, doubles, etc.) ARE NOT reference variables because they store the variables themselves. โ The โ==โ tests identity, not equality, use equals( ) to check for equality What null means, and how to check for null โ A very important principle is that, if a variable contains the null value, a method call should not be made on it. โ We cannot call a method if the variable does not refer to an object How to handle null parameter values in your methods โ To check for null parameter values in methods, we sometimes have to use an if-statement to test whether a variable contains null or not, before calling a method on that variable.
if (... actors.get( i ) ...//Desired condition(goal)) { Return actors.get( i ); } } // Find the last object List
โ How to specify generic parameters correctly โ When declaring variables โ When creating objects More for Lists โฆ How to access elements by position get( index of element ) How to insert or remove elements by position add( position desired , element ) remove( position desired ) How insertion/removal affects order โ Inserting puts moves position of everything to the right 1 โ Remove shifts everything after it to the left How to write a loop over list elements using an arithmetically-controlled loop for (int i = 0; i < size( ); i++) { Stuff here; } Methods that return values โฆ How to write methods that return values, and how to write methods that do not public return type (like int, String, boolean, Car) getMethod( ) { return something; } public void changeThis() { Changes something, no return; } How the return statement works โ Where a method contains a return statement, it is always the final statement of that method, because no further statements in the method will be executed once the return statement is executed. โ Used to returning a value to match the return type in the methodโs header. How to correctly declare the signature for a method that returns a value (of any type) โ Together, the name of a method and the parameter types found in its header are called the methodโs signature. Visibility modifier, return type, method name, parameters(if any)
โ next(); โ hasNext(); โ To read one line at a time โ nextLine(); โ hasNextLine(); โ To read int values โ nextInt(); โ hasNextInt() โ How to use a PrintWriter โ To print lines โ To print multiple pieces of output on the same line Arrays โ Difference between arrays and container classes like ArrayList โ Arrays have a fixed length, ArrayLists are dynamic in size. โ ArrayLists do not contain primitive data types (like int, float, double), it only contains Objects (autoboxing). Arrays can contain primitive and objects. โ To find length of an ArrayList, use size() โ To find length of an Array, use length โ For adding elements, in ArrayList we do the add()method while in arrays we use the assignment operator. โ Arrays can be multi dimensional, while ArrayList is always single dimensional โ How to declare variables/fields that refer to an array โ How to create array objects โ int[ ] numbers = {1, 2, 3, 4, 5}; โ int[ ] numbers = new int[ 20 ] (creates empty array of size 20) โ How to access or change elements in an array โ Arrays are objects (but without useful methods) โ What values an arrayโs cells are initialized to โ How to use a for-each loop to traverse an array. โ How to use a numeric for loop to traverse an array. 2D Arrays โ How to create, access, and manipulate a 2D array โ How to create โ Int[][] cells = new int[rows][columns]; โ How to access
โ cells[1][2] would return whatโs in the second row, third column. โ A 2D array is really an โarray of arraysโ โ How to use nested loops (numeric for loops, or for-each) to traverse all cells in a 2D array For (int i = 0; i < num.length; i++){ for (int j = 0; j < num[i].length; j++){ Num[i][j] = some value; Maps โ A map is a collection of key/value pairs of objects. As with the ArrayList, a map can store a flexible number of entries. โ One difference between the ArrayList and a map is that with a Map each entry is not an object, but a pair of objects. โ How to declare fields/variables that refer to maps โ How to create HashMap objects โ How to manipulate the information in a map โ Add a new key/value pair โ The put method inserts an entry into the map. The get method retrieves the value for a given key. โ put(key, value); โ get(key) returns the value; โ Replace a key/value pair โ Check to see if a key is defined โ containsKey(key) โ Look up the value associated with a key โ Get the mapโs size โ map.size(); โ How to use maps to represent a problemโs data Interfaces โ The difference between an interface and a class โ How to declare an interface โ What kinds of declarations are allowed (or prohibited) in an interface โ What visibility level is required on all items in an interface