Chapter 6 - More-Sophisticated Behaviour Flashcards
What is the
**static keyword **
used for
this is used to define class/static variables.
this is a java compiler feature that will automatically box(wrap) and unbox(unwrap) primitive types to/from there wrapper class when the context calls for it (such as adding a primitive type to a collection)
NOTE: we can do this explicitly but java will handle it for us
describe
autoboxing
How do we
call a static method in Java
We can call a static method in Java without creating an instance of the class. Instead, we can simply use the name of the class followed by the name of the method
in 3 points
How do constant declarations differ from field declarations in Java?
these differ in that
1. they include the final keyword before the type and name
2. must be initialized with a value at the point of declaration
3. are usually capitalized by convention.
what is the syntax and params of the String method
split()
Syntax for String method:
split(value)
@param value a character or regex that defines where to separate a string
why might we use a primitive types wrapper class
one reason inludes:
collections may only hold objects, if we tried to place a primitive type into a collection it would not be accepted
in this case we must create an object representing the primitive type using its associated wrapper class
this is the idea that different parts of a system are not strongly connected, and can be changed without affecting each other.
What is
weak or loose coupling
describe the String method
split()
this String method can be used to split a string by a given character or regex. The separated strings are then returned in an array of strings
Syntax for the ArrayList and HashSet method addAll():
Collection1.addAll(collection2)
what is the syntax of the ArrayList and HashSet method
addAll()
this String method will return a new string from the given string but with any leading and trailing whitespace removed
describe the String method
trim()
what is the following also known as
terneray operator
what is the following also known as
conditional operator
syntax:
substring(int beginIndex, int endIndex)
param:
beginIndex the beginning index, inclusive.
endIndex (optional) the ending index, exclusive.
give the syntax and params of the String method
substring()
information includes:
1.The name of the method
2.Purpose of the function or method
3.@param annotation - the name and type and description of a parameter
4.@return annotation - the type and a description of what is returned
name 4 pieces of
information that should be included in the Constructor and method documentation
describe the access modifier
public
this access modifier allows a member (e.g., a field, method, or class) to be accessed from anywhere. (e.g., outside the class it was defined)
Syntax:put(key, value)
@param key- key with which the specified value is to be associated
@param value- value to be associated with the specified key
what is the syntax and params of the HashMap method
put()
What are
class variables
also known as static variables, are variables that only have one copy, no matter how many instances of the class are created.
code:
Int anInt = 22 Integer aWrapper = new Integer(anInt);
write the code that would explicitly wrap a an int using its associated wrapper class
How do we define implementation and interface in a class?
We define the implementation using the private keyword, and the interface using the public keyword.
this class can be imported with the following statement
import java.util.Random;
how do we import the class Random
this is a documentation generator that is included with java
what is
javadoc
describe the
java.lang package
this package is automatically imported into every java program and contains commonly used classes such as
1. wrapper classes - Integer, Boolean, etc
2. String class
3. Math class
this is a method that is not for public use but helps to achieve publicly accessible operations.
It should be declared as private because it is part of the implementation of a class, and is not intended to be used by other classes or users.
What is a
helper method
We can call a static method in Java without creating an instance of the class. Instead, we can simply use the name of the class followed by the name of the method
How do we
call a static method in Java
the wrapper class has the same name as its associated primitive type except
1. we include a capital letter at the beggining
2. int uses wrapper class Integer
3. char uses wrapper class Character
what are the names of the wrapper classes for the primitive types