Java is an…
object-oriented programming language (organized in terms of objects)
What are objects?
A value that combines data and the code operating on that data into a single unit (specific instances of classes with defined attributes)
How do you define an object?
You write a class
What is a class?
A classification that defines a new data type that formally implements (the blueprint) the attributes and behaviors of the objects of that class
What does a class do?
classes define new data types that are like blueprints
What are attributes? (instances variable)
The properties or what each object knows about itself
What are behaviors? (methods)
What each object can do
What is a method signature? Give an example.
The method name followed by the param list that gives the name and type for each param. E.g. - public void inviteFriend ():
What is a NullPointerException?
Happens when you try to call an object method on an object variable with a null value. Usually means the oject was created without the new operator followed by the class name and ().
What is a static/class method? How is it different from a non-static/object method?
A static method is one that doesn’t need to be called on an object of a class. Object methods need to be called on an object of a class.
What operator do you use to run an object’s method?
The dot operator (.), the object, method name, and ending parenthesis. Eg. - yertle.forward()
What is procedural abstraction?
Allows a programmer to use a method by knowing generally what it does. Like how you can drive a car without knowing how the breaks work
What are arguments?
Data you can run into an object’s method
What are constructors?
Methods within each class used to initialize attributes in a newly created object (they have the same name as the class)
How do you create a new object?
Use the keyword “new” followed by the class name (Eg. new World()). When it runs, it will create a new object (instance) of that class and call a constructor that has the same name of the class (Eg. new World() creates and initializes a new object of the World class).
What is a no-argument constructor?
A constructor that doesn’t take any passed in values.
What is overloading (NOT AN ERROR)?
When there is more than one constructor defined in a class (E.g. World world1 = new World(); which calls it with default parameters, and World world2 = new World(width, height);). The parameter lists must differ in either number, order, or type of parameters to overload.
What does mixing up parameters do?
Cause an error (not the type of data expected, E.g. turtle parameters must always go x, y ,world)
What does null mean?
It says a variable has not been assigned a reference yet (no object to go find in memory). While Turtle t1 = new Turtle(20,20, world); declares that t1 is a turtle instance in Turtle, Turtle t1 = null; or Turtle t1; says that no value has been assigned yet.
What are constructor signatures (or headers)?
A constructor’s name and list of parameters. Can be used to overload a constructor.
What are parameters?
Things that allow values to be passed to the constructor to initialize the newly created object’s attributes
What is the difference between formal and actual parameters?
Formal parameters are in the constructor’s signature, while actual parameters are values passed into the constructor.
What does call by value mean?
When you pass a value to a constructor or method it passes a copy of the value
What do void methods return?
Nothing; the point of calling it is to have an effect (do things)
What do non-void methods do?
They return a value the code carrying the method call can use; the value returned tells us about the object’s internal state (produce values)
What is an accessor (getters)?
A method that accesses a value in an object, takes no arguments, and has a non-void return type (almost always starts with get, like getWidth)
What is a return statement (in a method)?
It returns the value output from the method, and must match the declared return type of the method. The calling method then uses that value.
What is a package?
The parent class of a class (For the String class, its in the java.lang package). Every class knows its parent class (superclass)
How do you cause implicit conversion of values to string values?
You concatenate them with a string object (“String” + nowAString + “String”)
List the escape sequences and what they do.
Within quotations, \” prints a quote, \\ prints a backslash, and \n prints a new line
What is an index?
A number associated with a string’s position. It begins at 0. One less than the length of a string (length starts at 1)
int length()
the number of characters in a string
String substring(int from, int up to but not including)
a new string that is a part of another string with 0 to all characters copied from the original string
immutable
doesn't change index the position of a character in a string
int indexOf(String str)
Returns the position of one string in another or -1
int compareTo(String other)
Returns a number to indicate if one string is less than (-difference), equal to (0), or greater than another (positive difference) (draw a greater or less than to find out)
Boolean equals(String other)
Returns true if the characters are the same, false otherwise
toString
Returns a string representing the object that is passed to this method
equals
Returns true if the characters in two strings are the same
Math.random() returns a random number between…
0.0-0.99.
What formula moves the random number into a range starting from a minimum number?
(int)(Math.random()*range) + min
How do you find the range?
max number - min number + 1
(int)(Math.random() * (max - min)) + min
write the permutation code